[Mono-bugs] [Bug 327608] BackgroundWorker: is UI-thread unsafe!

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Sep 26 09:05:13 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=327608#c7





--- Comment #7 from Andy Hume <andyhume32 at yahoo.co.uk>  2007-09-26 07:05:13 MST ---
Looks good, both the repro apps show correct behaviour.

However the 'book' samples again highlight a problem.  Showing a dialog causes
the WindowsFormsSynchronizationContext to be Uninstall-ed, and the default one
is used thereafter. :-(

I will attach a new repro app, a version of the second original one, but that
now shows MessageBox on completion.  If the "Start again" button is clicked
then the old bad behaviour is seen.

I had logging in SynchronizationContext and in SetSynchronizationContext added
logging of "new StackTrace()", it shows two calls, the second being the bad
one:
[[
[sc set]
   at
System.Threading.SynchronizationContext.SetSynchronizationContext(System.Threading.SynchronizationContext
syncContext)
   at System.Windows.Forms.Application.RunLoop(Boolean Modal,
System.Windows.Forms.ApplicationContext context)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)
   at BkgndWkr1.Main()
[sc get_Current]
[sc get_Current]
[sc get_Current]
[sc get_Current]
[sc set]
   at
System.Threading.SynchronizationContext.SetSynchronizationContext(System.Threading.SynchronizationContext
syncContext)
   at System.Windows.Forms.WindowsFormsSynchronizationContext.Uninstall()
   at System.Windows.Forms.Application.RunLoop(Boolean Modal,
System.Windows.Forms.ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window ownerWin32)
   at System.Windows.Forms.Form.ShowDialog()
   at System.Windows.Forms.MessageBox+MessageBoxForm.RunDialog()
   at System.Windows.Forms.MessageBox.Show(IWin32Window owner, System.String
text)
   at BkgndWkr1.bkgndWkr_RunWorkerCompleted(System.Object sender,
System.ComponentModel.RunWorkerCompletedEventArgs e)
   at
System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs
e)
   at
System.ComponentModel.BackgroundWorker+<>c__CompilerGenerated8.<CompleteWorker>c__33(System.Object
darg)
   at System.Reflection.MonoMethod.InternalInvoke(System.Object ,
System.Object[] )
   at System.Reflection.MonoMethod.InternalInvoke(System.Object ,
System.Object[] )
   at System.Reflection.MonoMethod.Invoke(System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(System.Object obj, System.Object[]
parameters)
   at System.Delegate.DynamicInvokeImpl(System.Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(System.Object[] args)
   at System.Delegate.DynamicInvoke(System.Object[] args)
   at System.Windows.Forms.XplatUIDriverSupport.ExecutionCallback(System.Object
state)
   at System.Security.SecurityContext.Run(System.Security.SecurityContext
securityContext, System.Threading.ContextCallback callBack, System.Object
state)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
executionContext, System.Threading.ContextCallback callBack, System.Object
state)
   at System.Windows.Forms.XplatUIDriverSupport.ExecuteClientMessage(GCHandle
gchandle)
   at System.Windows.Forms.XplatUIWin32.GetMessage(MSG ByRef msg, IntPtr hWnd,
Int32 wFilterMin, Int32 wFilterMax, Boolean blocking)
   at System.Windows.Forms.XplatUIWin32.GetMessage(System.Object queue_id, MSG
ByRef msg, IntPtr hWnd, Int32 wFilterMin, Int32 wFilterMax)
   at System.Windows.Forms.XplatUI.GetMessage(System.Object queue_id, MSG ByRef
msg, IntPtr hWnd, Int32 wFilterMin, Int32 wFilterMax)
   at System.Windows.Forms.Application.RunLoop(Boolean Modal,
System.Windows.Forms.ApplicationContext context)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)
   at BkgndWkr1.Main()
]]

Should there be an RunLoop inside a RunLoop?  Anyway we need not to Uninstall
in that case.

For completeness I also attach a expanded GetSyncCtx.cs sample, it shows that
on MSFT that the context is installed by Form creation and not Application.Run.
 Secondly that WFSC.AutoInstall is respected.  Probably both only used in the
rarest of applications however...
[[
$ GetSyncCtx.exe
At Main -- before new FooForm()
  SyncCtx.Current: NULL
At Main -- before Application.Run
  SyncCtx.Current: System.Windows.Forms.WindowsFormsSynchronizatio
At Form_Shown
  SyncCtx.Current: System.Windows.Forms.WindowsFormsSynchronizatio
At Main -- after Application.Run
  SyncCtx.Current: System.Threading.SynchronizationContext

$ GetSyncCtx.exe NO
Setting: WindowsFormsSynchronizationContext.AutoInstall = false
At Main -- before new FooForm()
  SyncCtx.Current: NULL
At Main -- before Application.Run
  SyncCtx.Current: NULL
At Form_Shown
  SyncCtx.Current: System.Threading.SynchronizationContext
At Main -- after Application.Run
  SyncCtx.Current: System.Threading.SynchronizationContext
]]

versus current Mono:

[[
$ mono GetSyncCtx.exe
t
At Main -- before new FooForm()
  SyncCtx.Current: NULL
At Main -- before Application.Run
  SyncCtx.Current: NULL
At Form_Shown
  SyncCtx.Current: System.Windows.Forms.WindowsFormsSynchronizationContext
At Main -- after Application.Run
  SyncCtx.Current: System.Threading.SynchronizationContext

$ mono GetSyncCtx.exe NO
Setting: WindowsFormsSynchronizationContext.AutoInstall = false
At Main -- before new FooForm()
  SyncCtx.Current: NULL
At Main -- before Application.Run
  SyncCtx.Current: NULL
At Form_Shown
  SyncCtx.Current: System.Windows.Forms.WindowsFormsSynchronizationContext
At Main -- after Application.Run
  SyncCtx.Current: System.Threading.SynchronizationContext
]]

Finally, EoL handling is not set on WFSC.cs in SVN.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list