문제

I have 2 decoupled classes, class A and class B, these two classes communicate with each other with event publication and event subscription using Mircosoft CAB framework :

public class ClassA
    {
        [EventPublication("ActionFired", PublicationScope.WorkItem)]
        public event EventHandler<EventArgs> ActionFired;

        public void MethodA()
        {
            // Some code 1
            DoAction1();
            // Some code 2
        }

        private void DoAction1()
        {
            if (ActionFired != null)
                ActionFired(this, EventArgs.Empty);
        }
    }

    public class ClassB
    {
        [EventSubscription("ActionFired")]
        public void OnActionFired(object sender, EventArgs e)
        {
            // Here some background work using BackgroundWorker
        }

        private void bagroudThread_DoWork(object sender, DoWorkEventArgs e)
        {
            // work 
        }

        private void bagroudThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {

         }
    }

Here in MethodA we call DoAction1(); that fire the event publication, the subscriber execute its handler in a background worker thread, the problem here that I want that 'some code 2' (that comes after calling DoAction1()) execute only after the background worker is completed, but here DoAction1() is executed asynchronously and 'some code 2' is executed before the classB background worker complete the work. How can I control the execution of MethodA?

Regards

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top