In C#, wait on the mainthread while continuing to process UI updates? (.NET 2.0 CF)

前端 未结 10 2199
梦谈多话
梦谈多话 2020-12-18 11:49

I want to otherwise block code execution on the main thread while still allowing UI changes to be displayed.

I tried to come up with a simplified example version of

10条回答
  •  误落风尘
    2020-12-18 12:27

    You should probably restructure your code as others have suggested, but depending on the behavior you're looking for, you might also want to have a look at using a Thread.Join on your background worker thread. Join actually allows the calling thread to process COM and SendMessage events while it waits for the other thread to finish. This seems like it could be dangerous in come cases, but I've actually had a couple scenarios where it was the only way to wait for another thread to finish cleanly.

    Thread..::.Join Method

    Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping.

    (from http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx)

提交回复
热议问题