Click here to Skip to main content
15,887,341 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using threds for processing xml files
for(i=0;i<200;i++)
{
Thread thread1 = new Thread(() => ProcessParadotProspect(dsXMLData, strFileName));
thread1.Start();

Thread thread2 = new Thread(() => ProcessVistorActivity(dsXMLData, prospect_id, strFileName));
thread2.Start();

Thread thread3 = new Thread(() => ProcessListSubscription(dsXMLData, prospect_id, strFileName));
thread3.Start();
}
but after 2 minutes System.OutOfMemoryException is coming

please tell me how to resolve

What I have tried:

ihave tried so many posts in google search but not getting correct solution please help out in this regard
Posted
Updated 6-Nov-18 0:00am
Comments
Richard MacCutchan 14-Oct-16 3:19am    
Do not create so many threads.

That creates 600 threads, and quite what the threads themselves do, we have no idea.
But...each thread requires a stack, which by default is a contiguous block of 1MB - so those thread (without anything they may be creating) will require 600 contiguous blocks of 1MB from your Process memory before anything else is counted. Depending on the system you are using, you may start to experience problems if the app is doing anything else, as some are limited to a 2GB Process total.

Why create that many? Do you think you have 600 cores to run them? Creating more threads than cores normally slows down total throughput rather than speeding it up as it adds to the task switching overhead enormously. I'd start by looking at what you are doing that you think requires that many simultaneous threads, then look at what the actual threads themselves are doing.

Sorry, but we can't do any of that for you!
 
Share this answer
 
I may be wrong, but it seems to me that you launch 200 times 3 threads with same parameters each time.
Are you sure you are not doing 200 times the same job ?
As far as I can see the 3 threads are processing 200 times the same FileName.
Did I miss something ?
 
Share this answer
 
Presumably the methods should be done one after another and not in parallel, and use Tasks instead so try:
C#
for(i=0;i<200;i++)
{
    Task.Factory.StartNew( () => {
        ProcessParadotProspect(dsXMLData, strFileName);
        ProcessVistorActivity(dsXMLData, prospect_id, strFileName);
        ProcessListSubscription(dsXMLData, prospect_id, strFileName)
    });
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900