Hi,
I have some generic module that handles exceptions. simply you call it like
this: "LogManager.Err orMessage(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
(MyExceptionFor m.ShowDialog) we get an System.Security .SecurityExcept ion
(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/libr...8(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.Threa d.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 .SecurityExcept ion was caught
Message="Reques t for the permission of type
'System.Securit y.Permissions.U IPermission, mscorlib, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9' failed."
Source="mscorli b"
StackTrace:
at System.Security .CodeAccessSecu rityEngine.Chec k(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security .CodeAccessPerm ission.Demand()
at System.Windows. Forms.NativeWin dow.CreateHandl e(CreateParams cp)
at System.Windows. Forms.Control.C reateHandle()
at System.Windows. Forms.Form.Crea teHandle()
at System.Windows. Forms.Control.g et_Handle()
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Form.Show Dialog(IWin32Wi ndow owner)
at System.Windows. Forms.Form.Show Dialog()
at LoggingManager. LogManager.Exce ptionToUI(LogEx ception MyException)
I have some generic module that handles exceptions. simply you call it like
this: "LogManager.Err orMessage(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
(MyExceptionFor m.ShowDialog) we get an System.Security .SecurityExcept ion
(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/libr...8(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.Threa d.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 .SecurityExcept ion was caught
Message="Reques t for the permission of type
'System.Securit y.Permissions.U IPermission, mscorlib, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9' failed."
Source="mscorli b"
StackTrace:
at System.Security .CodeAccessSecu rityEngine.Chec k(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security .CodeAccessPerm ission.Demand()
at System.Windows. Forms.NativeWin dow.CreateHandl e(CreateParams cp)
at System.Windows. Forms.Control.C reateHandle()
at System.Windows. Forms.Form.Crea teHandle()
at System.Windows. Forms.Control.g et_Handle()
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Form.Show Dialog(IWin32Wi ndow owner)
at System.Windows. Forms.Form.Show Dialog()
at LoggingManager. LogManager.Exce ptionToUI(LogEx ception MyException)
Comment