Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
AnswerRe: Download youtube with C#2005 ? Pin
M.Scheeren10-Nov-14 1:46
professionalM.Scheeren10-Nov-14 1:46 
GeneralRe: Download youtube with C#2005 ? Pin
Member 245846722-Nov-14 20:21
Member 245846722-Nov-14 20:21 
GeneralRe: Download youtube with C#2005 ? Pin
M.Scheeren23-Nov-14 19:57
professionalM.Scheeren23-Nov-14 19:57 
GeneralRe: Download youtube with C#2005 ? Pin
Member 245846726-Nov-14 20:09
Member 245846726-Nov-14 20:09 
GeneralRe: Download youtube with C#2005 ? Pin
M.Scheeren1-Dec-14 22:31
professionalM.Scheeren1-Dec-14 22:31 
QuestionHow to find duplicate Value from Datagridview Pin
Member 107170859-Nov-14 16:27
Member 107170859-Nov-14 16:27 
AnswerRe: How to find duplicate Value from Datagridview Pin
Richard MacCutchan9-Nov-14 21:48
mveRichard MacCutchan9-Nov-14 21:48 
QuestionWaiting for thread to exit? Pin
SledgeHammer018-Nov-14 17:07
SledgeHammer018-Nov-14 17:07 
I have a scenario where the application starts up and spawns a worker thread. When the main thread exits, I want the PROCESS (and the worker thread) to stay alive until its done doing its thing and then the whole process can exit. So I did something like this:

Thread threadCurrent = Thread.CurrentThread;

			Task.Run(() =>
			{
				while (threadCurrent.IsAlive || (_queue.Count > 0))
					Thread.Sleep(250);
			});


This does exactly what I want. When the main application exits, the process keeps running until the queue is finished processing (_queue is processed in a separate thread, this code piece keeps the process alive) and then the process shuts down.

I'm not happy with the Sleep(250) portion because that part is going for the entire lifetime of the application. It's not spinning the CPU or anything. I'm just looking for a better way to do it.

I tried threadCurrent.Join(), however, that only works if the app is running in the debugger. I don't get why. If I have a debugger attached, the Join() blocks until the main thread is done as expected. If I don't have a debugger attached, the Join() never returns.

EDIT: I should also note that this code in a library, so I can't really require the developer to do anything special in the main thread to make this work.
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult8-Nov-14 17:19
mvePIEBALDconsult8-Nov-14 17:19 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer018-Nov-14 17:24
SledgeHammer018-Nov-14 17:24 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult8-Nov-14 17:32
mvePIEBALDconsult8-Nov-14 17:32 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer018-Nov-14 17:39
SledgeHammer018-Nov-14 17:39 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak8-Nov-14 18:59
mveDave Kreskowiak8-Nov-14 18:59 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer018-Nov-14 19:20
SledgeHammer018-Nov-14 19:20 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak9-Nov-14 4:43
mveDave Kreskowiak9-Nov-14 4:43 
GeneralRe: Waiting for thread to exit? Pin
Eddy Vluggen9-Nov-14 5:59
professionalEddy Vluggen9-Nov-14 5:59 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:31
SledgeHammer019-Nov-14 7:31 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:28
SledgeHammer019-Nov-14 7:28 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 5:59
mvePIEBALDconsult9-Nov-14 5:59 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak9-Nov-14 7:08
mveDave Kreskowiak9-Nov-14 7:08 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:48
SledgeHammer019-Nov-14 7:48 
GeneralRe: Waiting for thread to exit? Pin
Dave Kreskowiak9-Nov-14 10:31
mveDave Kreskowiak9-Nov-14 10:31 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 11:18
SledgeHammer019-Nov-14 11:18 
GeneralRe: Waiting for thread to exit? Pin
SledgeHammer019-Nov-14 7:37
SledgeHammer019-Nov-14 7:37 
GeneralRe: Waiting for thread to exit? Pin
PIEBALDconsult9-Nov-14 7:54
mvePIEBALDconsult9-Nov-14 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.