Using Multithreading with Controls

When a thread creates a control, it "owns" that control. The .NET Compact Framework dictates that only the owner thread can make method calls to controls. If you call control methods from a non-owning thread, you risk causing your application to freeze. The .NET Compact Framework therefore provides the Control.Invoke method, which permits method execution on controls in a safe manner. You can’t call Control.Invoke from the thread that owns the control, but you can safely call the method from any other thread. Control.Invoke has two overloads:

public object Control.Invoke(Delegate method)
public virtual object Control.Invoke(Delegate method, Object[] args)

This code causes the execution of the specified delegate ...

Get Microsoft® .NET Compact Framework (Core Reference) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.