locked
Web Application. Safe to mix QueueUserWorkItem With async-await? RRS feed

  • Question

  • Our dev team wrote a non-async method (I'm not allowed to change it to async-await). But I do want to run some code on a thread. So from this sync method, I would like to run something like this:

    ManualResetEvent signalCompletion = new ManualResetEvent(false); oResult result = GetCustomer(custID, signalCompletion);

    ...more code here

    signalCompletion.WaitOne(); Customer customer = result.Customer;


    in reference to this method (it's all set in motion by an Ajax call from client javascript). 

    public oResult GetCustomer(int custID, ManualResetEvent signalCompletion){ //Another sync method. 
        oResult r = new oResult();
        ThreadPool.QueueUserWorkItem(async delegate	{
    	using (Northwind db = new Northwind())
    	{
    	  r.Customer = await QueryDbAsync(custID, db);
    	}
    	signalCompletion.Set();
         });
        return r;
    }
    
    Does this seem feasible? Or is it raising a lot of red flags?  I'm no expert on threading. 

    • Moved by CoolDadTx Tuesday, June 12, 2018 7:17 PM ASP.NET related
    Tuesday, June 12, 2018 6:36 PM

All replies

  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, June 12, 2018 7:17 PM
  • I posted in both, because I thought that MSDN forums is regarded as a different forum than Asp.Net forums. 

    Is there a rule against that?

    Wednesday, June 13, 2018 1:56 AM