lundi 20 avril 2015

Add components on form asynchronously

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?

Aucun commentaire:

Enregistrer un commentaire