Browse Source

MTA2STA uses MethodInvoker delegate

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@822 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
6fc4a6c9b2
  1. 20
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs

20
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs

@ -40,33 +40,33 @@ namespace Debugger
public void CallInSTA(MethodInvoker callDelegate) public void CallInSTA(MethodInvoker callDelegate)
{ {
CallInSTA(delegate { callDelegate(); return null; }, true); CallInSTA(callDelegate, true);
} }
public object CallInSTA(MethodInvokerWithReturnValue callDelegate) public object CallInSTA(MethodInvokerWithReturnValue callDelegate)
{ {
return CallInSTA(callDelegate, false); object returnValue = null;
CallInSTA(delegate { returnValue = callDelegate(); }, false);
return returnValue;
} }
object CallInSTA(MethodInvokerWithReturnValue callDelegate, bool mayAbandon) void CallInSTA(MethodInvoker callDelegate, bool mayAbandon)
{ {
if (hiddenForm.InvokeRequired == true) { if (hiddenForm.InvokeRequired == true) {
// Warrning: BeginInvoke will not pass exceptions if you do not use MethodInvoker delegate!
IAsyncResult async = hiddenForm.BeginInvoke(callDelegate); IAsyncResult async = hiddenForm.BeginInvoke(callDelegate);
// Firsy try... give it 1 second to run // Give it 1 second to run
if (async.AsyncWaitHandle.WaitOne(1000, true)) { if (!async.AsyncWaitHandle.WaitOne(1000, true)) {
return hiddenForm.EndInvoke(async);
} else {
// Abandon the call if possible // Abandon the call if possible
if (mayAbandon) { if (mayAbandon) {
System.Console.WriteLine("Callback time out! Unleashing thread."); System.Console.WriteLine("Callback time out! Unleashing thread.");
return null;
} else { } else {
System.Console.WriteLine("Warring: Call in STA is taking too long"); System.Console.WriteLine("Warring: Call in STA is taking too long");
return hiddenForm.EndInvoke(async); // Keep waiting hiddenForm.EndInvoke(async); // Keep waiting
} }
} }
} else { } else {
return callDelegate(); callDelegate();
} }
} }

Loading…
Cancel
Save