Timing issue - DGV refreshes before process amends the data

前端 未结 3 737
孤城傲影
孤城傲影 2021-01-24 05:05

I\'ve got a button on a form that starts a process which, after x (varies) seconds, changes some data in a database table Y. The call InitializeGridView() then refreshes the DGV

3条回答
  •  有刺的猬
    2021-01-24 06:03

    You can call p.WaitForExit() on the process, but don't do that on the main thread (ie in a buttonClick);

    You'll want something like:

    //untested
    private void btRunProcessAndRefresh_Click(object sender, EventArgs e)
    { 
        var p = Process.Start(@"\\fileserve\department$\ReportScheduler_v3.exe", "12"); 
        p.Exited += ProcessExited;
        p.EnableRaisingEvents = true;
        //InitializeGridView(); 
    }     
    
    void ProcessExited(object sender, EventArgs e)
    {
        InitializeGridView();    
    }
    

提交回复
热议问题