<p>In my application I have a window which I popup with small messages on it (think similar to tooltip). This window uses the layered attributes to draw alpha backgrounds etc.</p>

<p>If I have several of these windows open at once, and I click one with my mouse, when they disappear they cause my application to lose focus (it switches focus to the app behind the current one).</p>

<p>How do I stop any interaction in my window?</p>

[{'answer_id': 49810, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 1, 'selected': False, 'text': '<p>I use it quite often for tasks such as progress indication and background data loading\\processing.<br>\nRecently i found use case that is not supported out of box. It\'s "Overridable Task". However Patric Smacchia come up with nice <a href="http://codebetter.com/blogs/patricksmacchia/archive/2008/06/10/backgroundworker-closure-and-overridable-task.aspx" rel="nofollow noreferrer">solution</a>.</p>\n'}, {'answer_id': 49811, 'author': 'Gulzar Nazim', 'author_id': 4337, 'author_profile': 'https://Stackoverflow.com/users/4337', 'pm_score': 2, 'selected': False, 'text': '<p>BackgroundWorker makes things a lot easier. One thing I found the hard way is Backgroundworker itself has thread affinity even though it is supposed to hide the thread switching problem. It does not automatically switch to the UI thread in every case. It needs to be created and run from the UI thread for thread switching to happen properly.</p>\n'}, {'answer_id': 49818, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve used it once and was quite happy with it. Often, there is no need for "big" multithreading, but only for 2 Threads (UI and Worker), and it works really well without having to worry too much about the underlying Threading Logic.</p>\n'}, {'answer_id': 49836, 'author': 'DonkeyMaster', 'author_id': 5178, 'author_profile': 'https://Stackoverflow.com/users/5178', 'pm_score': 3, 'selected': True, 'text': "<p>Multithreaded programming is hard to grasp in the beginning (and veterans still fail sometimes) and BackgroundWorker makes it a bit easier to use. I like the fact that BackgroundWorker has functionality which is easy to implement but even easier to wrongly implement in a subtle way, like cancellation.\nI use it if I have and need a progress update, so I can display a meaningful progress bar. </p>\n\n<p>If not, I use a Thread (or borrow from the ThreadPool), because I don't need all the functionality of BackgroundWorker and am proficient enough with threads to start a Thread and wait for it to stop.</p>\n\n<p>As for delegates for non-related tasks, I use those of the Thread classes, like plain <code>void ThreadStart()</code>, or I create my own.</p>\n"}, {'answer_id': 49892, 'author': 'Tomas Pajonk', 'author_id': 4694, 'author_profile': 'https://Stackoverflow.com/users/4694', 'pm_score': 0, 'selected': False, 'text': '<p>@Gulzar Thank you for this piece of info : It needs to be created and run from the UI thread for thread switching to happen properly.</p>\n\n<p>One thing to watch for when using a background worker that I have found is exception handlings.</p>\n\n<p>If an exception is thrown on the async process it will not throw an exception to the main thread, the process will finish and BackgroundWorker RunWorkerCompleted event will fire with the error being hidden in the RunWorkerCompletedEventArgs.Error.</p>\n\n<p>I like the fact that BackgroundWorker has functionality which is easy to implement but even easier to wrongly implement in a subtle way, like cancellation.</p>\n'}, {'answer_id': 84059, 'author': 'Johnny Bravado', 'author_id': 12222, 'author_profile': 'https://Stackoverflow.com/users/12222', 'pm_score': -1, 'selected': False, 'text': "<p>My biggest issue with the background worker class is that there really is no way to know when the worker has finished due to cancellation. The BackgroundWorker does not expose the thread it uses so you can't use the standard techniques for synchronizing thread termination (join, etc.). You also can't just wait in a loop on the UI thread for it to end because the RunWorkerCompleted event will never end up firing. The hack I've always had to use is to simply set a flag and then start a timer that will continue checking for the background worker to end. But it's very messy and complicates the business logic.</p>\n\n<p>So it is great as long as you don't need to support deterministic cancellation.</p>\n"}]
['https://Stackoverflow.com/questions/49806', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/986/']