CarloMinds
CarloMinds

Reputation: 1991

wpf begininvoke for updating ui

Hello i am working with c# wpf. now problem is threading. I cannot access other thread the UI elements and when i using Dispatcher.BeginInvoke I cannot control Window. The calculate take about 5min. I want update calculate state to UI progressbar and move windows my self. Who can help me. :)

public delegate void TrainDelegate();

private void btnTrain_Click(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(DispatcherPriority.Background, new TrainDelegate(StartTrain));
}

in StartTrain function I called textbox.
like follow

Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(txtbTrainPath.Text);

It works but block main window. they said Begininvoke is non-block calling.
Could you please help me? What should be changed here?

Upvotes: 0

Views: 605

Answers (1)

GCamel
GCamel

Reputation: 622

ok, then

private void btnTrain_Click(object sender, RoutedEventArgs e)
{
    string myText = txtbTrainPath.Text;
    Task.Factory.StartNew( () => { StartTrain(myText); } );
}

Upvotes: 1

Related Questions