Click here to Skip to main content
15,890,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: Calling destructor in C# - observer pattern problem Pin
Henry Minute10-Feb-11 13:27
Henry Minute10-Feb-11 13:27 
AnswerRe: Calling destructor in C# - observer pattern problem Pin
AspDotNetDev10-Feb-11 13:58
protectorAspDotNetDev10-Feb-11 13:58 
AnswerRe: Calling destructor in C# - observer pattern problem Pin
DaveyM6910-Feb-11 21:28
professionalDaveyM6910-Feb-11 21:28 
QuestionCan you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 5:52
MacRaider410-Feb-11 5:52 
AnswerRe: Can you run the same function from two backgroundWorkers Pin
Ian Shlasko10-Feb-11 5:58
Ian Shlasko10-Feb-11 5:58 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 6:03
MacRaider410-Feb-11 6:03 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
Ian Shlasko10-Feb-11 6:15
Ian Shlasko10-Feb-11 6:15 
AnswerRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 6:18
sitebuilderLuc Pattyn10-Feb-11 6:18 
You can share code across threads as much as you like; and you can share read-only data. As soon as shared data starts to change though, you need to take precautions. Having both threads write to a single file is a recipe for trouble. Witgout precautions you might get any of the following:
1,2,3,4,5,50000001,50000002,50000003,50000004,50000005,6...
1,50000001,2,3,500000002,4,5,50000003...
1,5002,3,00001,500000002,4,5,50000003...


the third line should worry you.
Anyway, threads help when the problem is too much calculations (non-blocking CPU activity) or too much uncertainty in the exact sequence of operations (blocking CPU activity as in I/O), they don't help much (or at all) when the problem is memory bandwidth or peripheral bandwidth. Having two threads doing nothing but writing a file does not make sense to me, it will either go wrong or be slower than a single thread doing the same; having multiple threads doing many things including writing to a single file needs a different approach, probably one where data gets collected, not written, by several threads, then filed by a single thread.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 6:38
MacRaider410-Feb-11 6:38 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
PIEBALDconsult10-Feb-11 6:45
mvePIEBALDconsult10-Feb-11 6:45 
AnswerRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 6:46
sitebuilderLuc Pattyn10-Feb-11 6:46 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
AspDotNetDev10-Feb-11 7:27
protectorAspDotNetDev10-Feb-11 7:27 
GeneralRe: Can you run the same function from two backgroundWorkers [modified] Pin
PIEBALDconsult10-Feb-11 6:42
mvePIEBALDconsult10-Feb-11 6:42 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 7:44
MacRaider410-Feb-11 7:44 
GeneralRe: Can you run the same function from two backgroundWorkers [modified] Pin
MacRaider410-Feb-11 8:13
MacRaider410-Feb-11 8:13 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
PIEBALDconsult10-Feb-11 8:21
mvePIEBALDconsult10-Feb-11 8:21 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 8:40
MacRaider410-Feb-11 8:40 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 8:22
sitebuilderLuc Pattyn10-Feb-11 8:22 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 9:17
MacRaider410-Feb-11 9:17 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 9:52
sitebuilderLuc Pattyn10-Feb-11 9:52 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
PIEBALDconsult10-Feb-11 8:18
mvePIEBALDconsult10-Feb-11 8:18 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 8:28
MacRaider410-Feb-11 8:28 
AnswerRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 8:39
sitebuilderLuc Pattyn10-Feb-11 8:39 
GeneralRe: Can you run the same function from two backgroundWorkers Pin
MacRaider410-Feb-11 8:51
MacRaider410-Feb-11 8:51 
AnswerRe: Can you run the same function from two backgroundWorkers Pin
Luc Pattyn10-Feb-11 9:03
sitebuilderLuc Pattyn10-Feb-11 9:03 

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.