I'm working with WinForms I faced with following problem. I should dynamically create and add on form two tabs in concrete period of time.
This is main layout
IMainGeneralReportForm mainGeneralReportLayoutForm =
ObjectFactory.GetOrCreateView<IMainGeneralReportForm>();
I try add my elements in next way:
ObjectFactory.ShowView<IGeneralReportSimpleView>();
ObjectFactory.ShowView<IGeneralReportAdvancedSearchView>();
Methods ShowView works perfectly. But when I call methods one by one the performance of program is a bit slow. So I decided to use multithreading in next way:
MainGeneralReportForm generalReportForm = mainGeneralReportLayoutForm as MainGeneralReportForm
generalReportForm.Invoke(new SimpleViewDelegate(() =>
{
return ObjectFactory.ShowView<IGeneralReportSimpleView>()
}));
generalReportForm.Invoke(new AdvancedViewDelegate(() =>
{
return ObjectFactory.ShowView<IGeneralReportAdvancedSearchView>()
}));
private delegate IGeneralReportSimpleView SimpleViewDelegate();
private delegate IGeneralReportAdvancedSearchView AdvancedViewDelegate();
Those approaches work identically. Could you please give me an advice how to fix this problem with multithreading?
You can't multithread this way because they are both invoking the UI thread. You would need to create your general report form on a separate thread, then add your report to an object on your main UI thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With