Link to home
Start Free TrialLog in
Avatar of dingir
dingirFlag for Sweden

asked on

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,
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

can u post the code u using to handle the threading?
Avatar of dingir

ASKER

   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)
            {
            }
        }
    }
>>foreach (UserMessage usermsg in res)

what is res?
Avatar of dingir

ASKER

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

like

var res = from u in db.Users
                      select u;
Avatar of dingir

ASKER

Some more ideas..? :-)
Avatar of dingir

ASKER

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..
>>process get killed and spit this error on catch exception.

what kind of exception is been thrown?
Avatar of dingir

ASKER

That error is the topic of this thread,
Error: System.Threading.ThreadAbortException: Thread was being aborted.
does res is shared with all threads?
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dingir

ASKER

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,