Print Page | Close Window

Async Queries: handling sudden disconnect

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1004
Printed Date: 10-Jun-2026 at 7:09pm


Topic: Async Queries: handling sudden disconnect
Posted By: kjohnson
Subject: Async Queries: handling sudden disconnect
Date Posted: 19-Nov-2008 at 8:49am
The application I'm currently working on is using asynchronous queries to keep data up to date.  I'm also working to get my application to work while disconnected from the network.  The problem I am having is concerning sudden loss of network connectivity.  I've set up my program to detect when connectivity is lost (loss of network in a client-server, loss of internet in an n-tier), and then cancel the asynchronous queries until connectivity is restored.  Unfortunately, I'm getting an error that the 'operation has been canceled' when I cancel the async queries.

I'm canceling and restarting the async queries elsewhere without problems.  It is only during this sudden loss of connectivity situation I'm testing that I have a problem.  Is there a certain exception being thrown I'm not handling, or would you suggest another way to handle this situation?  Or is there documentation I missed that will help?



Replies:
Posted By: kimj
Date Posted: 19-Nov-2008 at 11:11am
In theory, a call to PM.CancelAsync() should succeed even if the operation was already cancelled -- is this where the exception is thrown? 
 
Depending on the timing of events, it's possible that you could see the connection failure in your PersistenceServerError handler.  When the PM detects connection failures it will also enter some retry logic, so that might be confusing things.
 
What version of DevForce are you using, and are you using WCF or remoting for communications to the BOS?  Can you also post the full text and stack trace of the exception?


Posted By: kjohnson
Date Posted: 19-Nov-2008 at 12:39pm
I'm using DevForce 3.6.3 and testing this scenario in a 2-tier client-server environment.  I'll try checking PersistenceServerError handler to see if anything is happening there.  As a note, the ResetAsyncQuery() and GetEntitiesCompleted Handler() listed in the exception text are unchanged from the async query tutorial.

************** Exception Text **************
System.InvalidOperationException: Operation has been cancelled.
   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
   at IdeaBlade.Persistence.GetEntitiesCompletedEventArgs.get_Entities()
   at FrontEnd.XtraMainForm2.ResetAsyncQuery(GetEntitiesCompletedEventArgs e)
   at FrontEnd.XtraMainForm2.GetEntitiesCompletedHandler(Object sender, GetEntitiesCompletedEventArgs e)
   at IdeaBlade.Persistence.PersistenceManager.OnGetEntitiesCompleted(GetEntitiesCompletedEventArgs pArgs)
   at IdeaBlade.Persistence.PersistenceManager.AsyncFetchCompleted(Object pFetchState)

Stack Trace:
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at FrontEnd.Program.Main() in \\optimus\Public\Kevin\RealTimePOS\Project Files\FrontEnd\FrontEnd\Program.cs:line 23


Posted By: kimj
Date Posted: 19-Nov-2008 at 5:37pm
Ah, okay.  The GetEntitiesCompletedHandler in that tutorial is not checking the GetEntitiesCompletedEventArgs to see if the operation was either cancelled or in error before trying to access the Entities property in ResetAsyncQuery().  These args are a subclass of System.ComponentModel.AsyncCompletedEventArgs, and the event-based pattern indicates that an exception should be raised when trying to access result properties after a cancel or error.  Here's more information: http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.aspx - http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.aspx .



Print Page | Close Window