worker-thread

Sleep(suspend) and Resuming windows form starts program on worker thread instead of main thread

大兔子大兔子 提交于 2019-12-06 11:28:15
The windows form I am working on subscribes to Microsoft.Win32.SystemEvents.PowerModeChanged and on Suspend it runs the Close() method on the form. On Resume it runs the Run() function like it would on initial load. The problem is that when the computer is woken from sleep mode the PowerModeChanged event is triggered on a worker thread named ".Net SystemEvents" and when Run() is called it recreates the form on this worker thread instead of the main thread. This form is a project I inherited from another developer and I am new to windows form programming. I am wondering if there is a better way

How can I tell if a thread is finished executing without polling ThreadState?

烈酒焚心 提交于 2019-12-04 16:03:48
Is there an elegant way to know when a worker thread is done executing so I can access resources it produced? For example if the worker thread queried a list of SQL Servers using ServersSqlDataSourceEnumerator.Instance.GetDataSources(); and saved the result in a DataTable variable, what mechanism can I use to know when this DataTable variable has been populated/is available. I don't want to poll ThreadState; it would be ideal to fire an event when it's done so I can perform actions with the result. Thanks! You can use a callback mechanism or block on an event to know of completion of an Async

Proper way to have an endless worker thread?

被刻印的时光 ゝ 提交于 2019-12-03 02:52:16
问题 I have an object that requires a lot of initialization (1-2 seconds on a beefy machine). Though once it is initialized it only takes about 20 miliseconds to do a typical "job" In order to prevent it from being re-initialized every time an app wants to use it (which could be 50 times a second or not at all for minutes in typical usage), I decided to give it a job que, and have it run on its own thread, checking to see if there is any work for it in the que. However I'm not entirely sure how to

Proper way to have an endless worker thread?

人盡茶涼 提交于 2019-12-02 16:26:00
I have an object that requires a lot of initialization (1-2 seconds on a beefy machine). Though once it is initialized it only takes about 20 miliseconds to do a typical "job" In order to prevent it from being re-initialized every time an app wants to use it (which could be 50 times a second or not at all for minutes in typical usage), I decided to give it a job que, and have it run on its own thread, checking to see if there is any work for it in the que. However I'm not entirely sure how to make a thread that runs indefinetly with or without work. Here's what I have so far, any critique is

Execute long running operations on the service

南笙酒味 提交于 2019-11-29 16:15:05
I'm building an application which have a Service. I know that all application components run in the same UI process, at least you specify it in the manifest. So to avoid ANR's messages i have three ways. Specify the service in the manifest to run in a separate process like android:process=":remote" but i've read some StackOverflow's post that says that it's not a good idea, because it consume a lot of battery and cpu processing. That i really respect since those post are from trusted people. Use an IntentService. it's probably a good way out. but i need my service running even if the activity

PostMessage from WorkerThread to Main Window in MFC

房东的猫 提交于 2019-11-29 10:21:55
I have a MFC application, which has a worker thread, what I want to do is to post message from worker thread to the Main GUI thread to update some status messages on GUI. What I have done so far is Registered a new window message //custom messages static UINT FTP_APP_STATUS_UPDATE = ::RegisterWindowMessageA("FTP_APP_STATUS_UPDATE"); Added this message to the message map of dialog class ON_MESSAGE(FTP_APP_STATUS_UPDATE, &CMFC_TestApplicationDlg::OnStatusUpdate) The prototype of OnStatusUpdate is afx_msg LRESULT OnStatusUpdate(WPARAM, LPARAM); and definition is LRESULT CMFC_TestApplicationDlg:

Execute long running operations on the service

旧时模样 提交于 2019-11-28 10:08:14
问题 I'm building an application which have a Service. I know that all application components run in the same UI process, at least you specify it in the manifest. So to avoid ANR's messages i have three ways. Specify the service in the manifest to run in a separate process like android:process=":remote" but i've read some StackOverflow's post that says that it's not a good idea, because it consume a lot of battery and cpu processing. That i really respect since those post are from trusted people.

PostMessage from WorkerThread to Main Window in MFC

拈花ヽ惹草 提交于 2019-11-28 03:53:03
问题 I have a MFC application, which has a worker thread, what I want to do is to post message from worker thread to the Main GUI thread to update some status messages on GUI. What I have done so far is Registered a new window message //custom messages static UINT FTP_APP_STATUS_UPDATE = ::RegisterWindowMessageA("FTP_APP_STATUS_UPDATE"); Added this message to the message map of dialog class ON_MESSAGE(FTP_APP_STATUS_UPDATE, &CMFC_TestApplicationDlg::OnStatusUpdate) The prototype of OnStatusUpdate