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

C#

 
GeneralRe: How to loop in timers Pin
Member 1107411510-Sep-14 22:02
Member 1107411510-Sep-14 22:02 
GeneralRe: How to loop in timers Pin
OriginalGriff10-Sep-14 22:09
mveOriginalGriff10-Sep-14 22:09 
GeneralRe: How to loop in timers Pin
Member 1107411510-Sep-14 22:41
Member 1107411510-Sep-14 22:41 
GeneralRe: How to loop in timers Pin
OriginalGriff10-Sep-14 22:57
mveOriginalGriff10-Sep-14 22:57 
GeneralRe: How to loop in timers Pin
Member 1107411524-Sep-14 19:56
Member 1107411524-Sep-14 19:56 
QuestionThreading issue Pin
SledgeHammer0110-Sep-14 10:23
SledgeHammer0110-Sep-14 10:23 
AnswerRe: Threading issue Pin
PIEBALDconsult10-Sep-14 11:29
mvePIEBALDconsult10-Sep-14 11:29 
GeneralRe: Threading issue Pin
SledgeHammer0110-Sep-14 12:14
SledgeHammer0110-Sep-14 12:14 
No, I want the app to NOT exit after spawning off threads...

1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
3) main thread "exits", but only unit of work 1..30 were processed because the main thread exited too fast

What I want instead is:

1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
3) main thread "exits", BUT "PROCESS HANGS" until all 1000 units of work are completed

I know I can do this with a .Join in the main thread, but as I said in my original post is that Foo() is its own man. If it wants to "block the process from exiting" until all the work is completed, it should do so without the main threads assistance.

Seems like when *Tasks* are running, they don't block the process from exiting
Seems like when a *Thread* object is running, it blocks the process from exiting

I kind of got something working, but I'm not super happy with it.

I kick off a Thread so the process is blocked from exiting... the background thread does a BlockingCollection.Take with a cancellation token. If the cancellation token is set, it exits the background thread.

Meanwhile, I also kick off a main thread watch dog task that checks if the main thread has exited and if it does, AND the queue is empty it sets the cancellation token so the background thread can exit.

It does have the behavior I want, but I'm not really liking this part:

Thread threadCurrent = Thread.CurrentThread;

Task.Run(() =>
{
if (System.Diagnostics.Debugger.IsAttached)
threadCurrent.Join();

Console.WriteLine("EXITED");

while (_queueLogEntries.Count > 0)
{
Thread.Sleep(100);
}

Console.WriteLine("EXITED2");

_cts.Cancel();
});
GeneralRe: Threading issue Pin
PIEBALDconsult10-Sep-14 15:18
mvePIEBALDconsult10-Sep-14 15:18 
Questionwebrowser control Pin
Member 1105956910-Sep-14 8:26
Member 1105956910-Sep-14 8:26 
AnswerRe: webrowser control Pin
Eddy Vluggen10-Sep-14 8:29
professionalEddy Vluggen10-Sep-14 8:29 
Generalwebrowser control Pin
Member 1105956910-Sep-14 8:42
Member 1105956910-Sep-14 8:42 
GeneralRe: webrowser control Pin
Eddy Vluggen10-Sep-14 9:57
professionalEddy Vluggen10-Sep-14 9:57 
GeneralRe: webrowser control Pin
Member 1105956912-Sep-14 9:50
Member 1105956912-Sep-14 9:50 
GeneralRe: webrowser control Pin
Eddy Vluggen12-Sep-14 11:00
professionalEddy Vluggen12-Sep-14 11:00 
GeneralRe: webrowser control Pin
Member 1105956913-Sep-14 23:36
Member 1105956913-Sep-14 23:36 
Questionadd code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten9-Sep-14 18:40
KaKoten9-Sep-14 18:40 
AnswerRe: add code to build millisecond to testing progressbar in c# 2008 Pin
PIEBALDconsult9-Sep-14 19:45
mvePIEBALDconsult9-Sep-14 19:45 
GeneralRe: add code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten11-Sep-14 1:39
KaKoten11-Sep-14 1:39 
AnswerRe: add code to build millisecond to testing progressbar in c# 2008 Pin
CPallini9-Sep-14 19:59
mveCPallini9-Sep-14 19:59 
GeneralRe: add code to build millisecond to testing progressbar in c# 2008 Pin
KaKoten11-Sep-14 1:39
KaKoten11-Sep-14 1:39 
QuestionAny **FAST** way to convert IEnumerable to IEnumerable<T>? Pin
SledgeHammer019-Sep-14 18:16
SledgeHammer019-Sep-14 18:16 
GeneralRe: Any **FAST** way to convert IEnumerable to IEnumerable<T>? Pin
PIEBALDconsult9-Sep-14 19:42
mvePIEBALDconsult9-Sep-14 19:42 
GeneralRe: Any **FAST** way to convert IEnumerable to IEnumerable<T>? Pin
SledgeHammer019-Sep-14 20:07
SledgeHammer019-Sep-14 20:07 
GeneralRe: Any **FAST** way to convert IEnumerable to IEnumerable<T>? Pin
Pete O'Hanlon9-Sep-14 20:46
mvePete O'Hanlon9-Sep-14 20:46 

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.