P
Pieter
Hi,
I have some generic module that handles exceptions. simply you call it like
this: "LogManager.ErrorMessage(ex)".
Worked great, until we now discovered that it isn't Thread-safe. What
actially happens is this: A Form is made, labels and buttons are made etc
with the exception-details, but when trying to show the Form
(MyExceptionForm.ShowDialog) we get an System.Security.SecurityException
(see udnerneath for more info).
Seems completely normal to me, because we are accessing the UI from another
Thread. But how to find a solution?
Thanks a lot in advance,
Pieter
PS 1 : I see 2 possiblities:
1. Call InvokeRequired with Invoke like we usally do when accessing controls
from another thread
(http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx). BUT:
MyExceptionForm.InvokeRequired returns false... I guess this is because it
has been constructed in a background Thread?
2. To get around this problem: Figure out when we are on a background thread
(via Threading.Thread.CurrentThread.IsBackground: is this true??) and than
get via an event an an Invoke or something like that on the Main-htread and
call the form from there?
3. ...
PS 2: The exception when doing a MyExceptionForm.ShowDialog:
System.Security.SecurityException was caught
Message="Request for the permission of type
'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
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.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at LoggingManager.LogManager.ExceptionToUI(LogException MyException)
I have some generic module that handles exceptions. simply you call it like
this: "LogManager.ErrorMessage(ex)".
Worked great, until we now discovered that it isn't Thread-safe. What
actially happens is this: A Form is made, labels and buttons are made etc
with the exception-details, but when trying to show the Form
(MyExceptionForm.ShowDialog) we get an System.Security.SecurityException
(see udnerneath for more info).
Seems completely normal to me, because we are accessing the UI from another
Thread. But how to find a solution?
Thanks a lot in advance,
Pieter
PS 1 : I see 2 possiblities:
1. Call InvokeRequired with Invoke like we usally do when accessing controls
from another thread
(http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx). BUT:
MyExceptionForm.InvokeRequired returns false... I guess this is because it
has been constructed in a background Thread?
2. To get around this problem: Figure out when we are on a background thread
(via Threading.Thread.CurrentThread.IsBackground: is this true??) and than
get via an event an an Invoke or something like that on the Main-htread and
call the form from there?
3. ...
PS 2: The exception when doing a MyExceptionForm.ShowDialog:
System.Security.SecurityException was caught
Message="Request for the permission of type
'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
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.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at LoggingManager.LogManager.ExceptionToUI(LogException MyException)