Re: a few issues with events
- From: not_a_commie <notacommie@xxxxxxxxx>
- Date: Sat, 08 Sep 2007 10:48:21 -0700
Thanks for the response, Control.Invoke very definitely locks on
"this." If you open it with the reflector you'll see this:
public object Invoke(Delegate method, params object[] args)
{
using (MultithreadSafeCallScope scope = new
MultithreadSafeCallScope())
{
return this.FindMarshalingControl().MarshaledInvoke(this,
method, args, true);
}
}
private Control FindMarshalingControl()
{
lock (this)
{
Control parentInternal = this;
while ((parentInternal != null) && !
parentInternal.IsHandleCreated)
{
parentInternal = parentInternal.ParentInternal;
}
if (parentInternal == null)
{
parentInternal = this;
}
return parentInternal;
}
}
private object MarshaledInvoke(Control caller, Delegate method,
object[] args, bool synchronous)
{
int num;
if (!this.IsHandleCreated)
{
throw new
InvalidOperationException(SR.GetString("ErrorNoMarshalingThread"));
}
if (((ActiveXImpl) this.Properties.GetObject(PropActiveXImpl)) !=
null)
{
IntSecurity.UnmanagedCode.Demand();
}
bool flag = false;
if ((SafeNativeMethods.GetWindowThreadProcessId(new
HandleRef(this, this.Handle), out num) ==
SafeNativeMethods.GetCurrentThreadId()) && synchronous)
{
flag = true;
}
ExecutionContext executionContext = null;
if (!flag)
{
executionContext = ExecutionContext.Capture();
}
ThreadMethodEntry entry = new ThreadMethodEntry(caller, method,
args, synchronous, executionContext);
lock (this)
{
if (this.threadCallbackList == null)
{
this.threadCallbackList = new Queue();
}
}
lock (this.threadCallbackList)
{
if (threadCallbackMessage == 0)
{
threadCallbackMessage =
SafeNativeMethods.RegisterWindowMessage(Application.WindowMessagesVersion
+ "_ThreadCallbackMessage");
}
this.threadCallbackList.Enqueue(entry);
}
if (flag)
{
this.InvokeMarshaledCallbacks();
}
else
{
UnsafeNativeMethods.PostMessage(new HandleRef(this,
this.Handle), threadCallbackMessage, IntPtr.Zero, IntPtr.Zero);
}
if (!synchronous)
{
return entry;
}
if (!entry.IsCompleted)
{
this.WaitForWaitHandle(entry.AsyncWaitHandle);
}
if (entry.exception != null)
{
throw entry.exception;
}
return entry.retVal;
}
.
- Follow-Ups:
- Re: a few issues with events
- From: Peter Duniho
- Re: a few issues with events
- References:
- a few issues with events
- From: not_a_commie
- Re: a few issues with events
- From: Peter Duniho
- a few issues with events
- Prev by Date: Re: a few issues with events
- Next by Date: Re: Mixed language programming
- Previous by thread: Re: a few issues with events
- Next by thread: Re: a few issues with events
- Index(es):
Relevant Pages
|