[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Error: System.Threading.ThreadAbortException: Thread was being aborted.

This is the error I recieve when using my newly (and newbied) multi threading environment.

What I want is that this never should occur.

The situation above is that a user run a function from a webpage. That function does some things that can take 5-120 (or more) minutes to complete. If another user doing the same process (but with his/hers set of records from database) the already existing process get killed and spit this error on catch exception.

How do I make every click on that function/button to start on a unique/new/free thread/threadpool?! If the CPU is busy, the new thread should just sit and wait..

Thanks in advanced,
0
dingir
Asked:
dingir
  • 6
  • 5
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
can u post the code u using to handle the threading?
0
 
dingirAuthor Commented:
   protected void Page_Load(object sender, EventArgs e)
    {
        System.Threading.Thread ts = System.Threading.Thread.CurrentThread;
    }


    protected void bnSend_Click(object sender, EventArgs e)
    {
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(StartSendThread));
    }



    protected void StartSendThread(object state)
    {
        DataContext db = new DataContext();
        Server.ScriptTimeout = 99932323;
        Session.Timeout = 525600;

        foreach (UserMessage usermsg in res)
        {
            try
            {
                usermsg.Send();
            }
            catch (System.Threading.ThreadAbortException tae)
            {
            }
        }
    }
0
 
Meir RivkinFull stack Software EngineerCommented:
>>foreach (UserMessage usermsg in res)

what is res?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dingirAuthor Commented:
the res contains the result of a linq'ed DataContext db = new DataContext();

like

var res = from u in db.Users
                      select u;
0
 
dingirAuthor Commented:
Some more ideas..? :-)
0
 
dingirAuthor Commented:
Why can't I just choose to create a new thread or reuse same? Like every thread got a unique identifier that I want to attach, kill, check state of or being sure that next thread has another id..
0
 
Meir RivkinFull stack Software EngineerCommented:
>>process get killed and spit this error on catch exception.

what kind of exception is been thrown?
0
 
dingirAuthor Commented:
That error is the topic of this thread,
Error: System.Threading.ThreadAbortException: Thread was being aborted.
0
 
Meir RivkinFull stack Software EngineerCommented:
does res is shared with all threads?
0
 
Meir RivkinFull stack Software EngineerCommented:
u might put a simple lock when accesing res, something like:
lock (this)
      {
  foreach (UserMessage usermsg in res)
        {
            try
            {
                usermsg.Send();
            }
            catch (System.Threading.ThreadAbortException tae)
            {
            }
        }

}
0
 
dingirAuthor Commented:
I did the trix followed some guides that avoid the iis worker process from recycling and restarting..

also I did a exe file to do a schematic work.. that avoids all possible errors based on time running,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now