Your issue is the fact that the Toast
is being CREATED on another thread. What you'll likely need to do is have a "target" on the main UI thread where you can Invoke()
the creation AND showing of the Toast
, keeping all UI on the same thread.
EDIT
If you need to be able to keep this on another thread, your only other option is to create another thread with a message loop.
Thread t = new Thread();
t.SetApartmentState(ApartmentState.STA) // Required for a UI thread
As to the implementation of dispatching tasks and messages to this thread, I'll leave that up to you. You'll need to call Application.Run()
at the start of it in order to start your message loop.
And, as always, you'll have to be sure to Invoke()
any operations from your Toast (or anything on this thread) that may interact with the main UI thread.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…