1

I am new to writing multi-threaded apps in asp.net. I have a main class that It suppose to send bulk email which take a long time. So, I use a thread in main method to show a template page to user which shows your emails will be send and then it return to main method and continue to send these email. in main method :

ThreadStart job = new ThreadStart(showresult);
Thread thread = new Thread(job);
thread.Start();
SENDEMAILMETHOD();

and in showresult method :

public void showresult ()
    {
    try{    
            string showresulttemplate = File.ReadAllText (Path.GetFullPath (Server.MapPath ("~/templates/messaging/showresult.tpl")));
                    DotLiquid.Template liquidresultshow = Template.Parse (showresulttemplate);
                    Response.Write (liquidresultshow.Render ());  

        } catch (Exception ex ) {
                Logger.Error ( ex.ToString () );
    }
    }

what's wrong with my code or logic?

Farhad
  • 205
  • 1
  • 6
  • 13
  • Have you heard of TaskFactory ? http://msdn.microsoft.com/en-IN/library/system.threading.tasks.taskfactory.aspx – Prabhu Murthy Apr 27 '13 at 08:59
  • What error are you getting ? – Prabhu Murthy Apr 27 '13 at 09:01
  • I get No error but it seems thread doesn't execute properly because It doesn't show the template page and go to the SENDEMAILMETHOD() immediately. – Farhad Apr 27 '13 at 09:52
  • 2
    Why are you using the thread to show the template? Why not use the tread to send the emails? It is a bad idea to use the thread for GUI functions, keep those in the main thread. – Bit Apr 27 '13 at 10:19
  • If I use thread to send email I will need to send arguments to email function and I don't know how can I do it! – Farhad Apr 27 '13 at 11:01
  • check this out http://stackoverflow.com/questions/3360555/how-to-pass-parameters-to-threadstart-method-in-thread – Bit Apr 27 '13 at 21:32

0 Answers0