Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void FillDataAsnych(ActionControl ac)
- {
- m_Logger.Debug("FillDataAsnych");
- ac.Enabled = false;
- BackgroundWorker bw = new BackgroundWorker();
- bw.DoWork += GetDetailsWork;
- bw.RunWorkerCompleted += OnGetDetailsCompleted;
- bw.RunWorkerAsync(ac);
- }
- private void GetDetailsWork(object sender, DoWorkEventArgs e)
- {
- m_Logger.Debug("GetDetailsWork");
- ActionControl ac = (ActionControl)e.Argument;
- e.Result = GetDataForDetailedActionUpdate(ac.ActionCode);
- }
- private RawActionDetails GetDataForDetailedActionUpdate(string actionCode)
- {
- m_Logger.Debug("GetDataForDetailedActionUpdate");
- RawActionDetails res = new RawActionDetails(actionCode);
- DataTable dt = Globals.bse.GetActionByCode(actionCode); // this is a WCF call to the server returning a DataTable
- if (dt == null || dt.Rows.Count < 1)
- {
- return res;
- }
- res.action = dt.Rows[0];
- DataTable dtUsers = Globals.bse.GetAgentsOfAbility(actionCode);
- if (dtUsers == null)
- {
- return res;
- }
- res.users = dtUsers;
- DataTable dtMarkDFields = Globals.bse.GetMarkDFields(actionCode);
- if (dtMarkDFields == null)
- {
- return res;
- }
- res.fields = dtMarkDFields;
- res.complete = true;
- return res;
- }
- private void OnGetDetailsCompleted(object sender, RunWorkerCompletedEventArgs e) // no other code call this method, only the background worker above
- {
- m_Logger.Debug("OnGetDetailsCompleted");
- BackgroundWorker bw = (BackgroundWorker) sender;
- RawActionDetails bwr = (RawActionDetails)e.Result;
- lock (actionToControlMapSynchRoot)
- {
- actionToControlMap[bwr.actionCode].Enabled = true;
- }
- if (bwr.complete)
- {
- OnActionDetailsArrived(bwr);
- }
- }
- // this is not called by OnGetDetailsCompleted exclusively there is one more backgroundworker end event calling this
- private void OnActionDetailsArrived(RawActionDetails bwr)
- {
- m_Logger.Debug("OnActionDetailsArrived");
- DataRow dr = bwr.action;
- DataTable dtUsers = bwr.users;
- DataTable dtFields = bwr.fields;
- ActionClass acc = new ActionClass(dr, dtFields, false);
- Globals.actions.Change(acc);
- ActionControl ac;
- lock (actionToControlMapSynchRoot)
- {
- if (!actionToControlMap.ContainsKey(bwr.actionCode))
- {
- CFAPControlLibrary.Service<ICFAPService>.Use(srv =>
- {
- srv.Log(string.Format("Client: cannot find the action {0} in the control map", bwr.actionCode));
- });
- return;
- }
- ac = actionToControlMap[bwr.actionCode];
- }
- ac.FillData(Globals.actions.GetByCode(ac.ActionCode));
- PropertyBox.Base baseControl = ac.GetBaseControl();
- AgentSelector agntControl = ac.GetAgentControl();
- if (agntControl != null)
- {
- agntControl.FillSelectedAgents(dtUsers);
- }
- actionSelector1.FillNodes();
- }
- //The other chain calling OnActionDetailsArrived:
- // this is called on application startup and in some button handlers, but the hang occures even when none of these buttons are pressed
- private void LoadInitialValues()
- {
- m_Logger.Debug("LoadInitialValues");
- if (wic == null)
- {
- wic = new WaitingInfoControl();
- }
- Controls.Add(wic);
- int x = (this.Width - wic.Width) / 2;
- int y = (this.Height - wic.Height) / 2;
- wic.Left = x < 0 ? 0 : x;
- wic.Top = y < 0 ? 0 : y;
- wic.BringToFront();
- wic.Show();
- BackgroundWorker bw = new BackgroundWorker();
- bw.RunWorkerCompleted += bw_RunWorkerCompleted; // here is the end event setup
- bw.ProgressChanged += bw_ProgressChanged;
- bw.DoWork += DoGetAllDataWork;
- bw.WorkerReportsProgress = true;
- lock (actionToControlMapSynchRoot)
- {
- foreach (ActionControl ac in actionToControlMap.Values)
- {
- ac.Enabled = false;
- }
- bw.RunWorkerAsync(
- from openedActionCode in actionToControlMap.Keys where Globals.actions.GetByCode(openedActionCode) != null select openedActionCode
- );
- }
- SetEnabledControls(false);
- }
- private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- m_Logger.Debug("bw_RunWorkerCompleted");
- SetEnabledControls(true);
- Controls.Remove(wic);
- wic.Dispose();
- wic = null;
- actionSelector1.FillNodes();
- lock (actionToControlMapSynchRoot)
- {
- foreach (ActionControl ac in actionToControlMap.Values)
- {
- ac.Enabled = true;
- }
- if (e.Result is IEnumerable<RawActionDetails>)
- {
- IEnumerable<RawActionDetails> results = (IEnumerable<RawActionDetails>)e.Result;
- foreach (RawActionDetails rawData in results)
- {
- OnActionDetailsArrived(rawData); // the actual call
- }
- }
- foreach (ActionControl ac in actionToControlMap.Values)
- {
- ac.Enabled = true;
- }
- }
- }
- // this is probably irrelevant
- public class RawActionDetails
- {
- public string actionCode;
- public DataRow action;
- public DataTable users;
- public DataTable fields;
- public bool complete;
- public RawActionDetails(string pActionCode, DataRow pAction, DataTable pUsers, DataTable pFields)
- {
- actionCode = pActionCode;
- action = pAction;
- users = pUsers;
- fields = pFields;
- complete = true;
- }
- public RawActionDetails(string pActionCode)
- {
- actionCode = pActionCode;
- complete = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement