-1

I am currently working on forms in Enterprise Architect using C# add-ins. I am not using form.ShowDialog() because it had previously led to not-responding state of Enterprise Architect.

The backend process is Enterprise Architect which has to kept as parent to the current form which works on using form.Show() but the problem is when the form is exited with form.close(),EA is also getting minimized.

Kindly help me to display and close form such that EA will not get minimized after form close. Thanks in advance.

 class CreateContentsForForm
{
     ModifyForm()
   {        
        Form newForm=new Form();
       //adding contents to form

       //display form
        var proc = Process.GetProcesses().Where(x => x.ProcessName == "EA").First();
        IWin32Window w = Control.FromHandle(proc.MainWindowHandle);
        Form.Show(w); 
        Application.Run();//this is added for navigating through datagridview using tab key in form
   }
 }
rashmi
  • 203
  • 1
  • 8
  • Please kindly provide a [mcve]. – Enigmativity Nov 24 '17 at 05:12
  • I have edited the question.please check – rashmi Nov 24 '17 at 05:28
  • I've use both modal as non modal forms in EA add-ins and I've never had EA not responding, or getting minimized. – Geert Bellekens Nov 24 '17 at 07:52
  • @GeertBellekens I am displaying a form on element double clicked through EA_OnContextItemDoubleClicked and then update datagridview and textboxes in the form, by which new attributes will get added to element and tagged values will be updated. After this, I use Repository.RefreshOpenDiagrams(true) followed by form.Close(). The form closes and EA also gets minimized – rashmi Nov 24 '17 at 09:02
  • As I said, I've never had that problem. So I guess you could either look at my code at github and figure out why your code behaves differently, or you could provide a MCVE so others can help you figure out what might cause this behavior. – Geert Bellekens Nov 24 '17 at 09:18
  • Sure..I'll do that..thank you – rashmi Nov 24 '17 at 09:35
  • 1
    `Form newForm=new Form();` Then we never see you use newForm again. – LarsTech Jan 06 '18 at 22:27

2 Answers2

0

If EA goes to Not responding mode from your addin

Possibilities:

  • Addin deals with large model
  • Code logics needs to be optimised .

So in that case please use backgroundWorker in winforms.

backgroundWorker1_DoWork

backgroundWorker1_RunWorkerCompleted

This should do the trick.

Community
  • 1
  • 1
Dah Sra
  • 4,107
  • 3
  • 30
  • 69
  • I would not recommend using a backgroundworker to show forms. I would even say that using a backgroundworker is a last resort after ruling out all other possibilities. Going multi-threaded opens an whole new can of worms. – Geert Bellekens Nov 28 '17 at 13:01
-1

As a workaround, rather than closing the Form, you could hide the Form instead:

Form.Hide(w); 
dbc
  • 104,963
  • 20
  • 228
  • 340
  • Hello, and welcome to stackoverflow. Did you mean [`newForm.Hide()`](https://msdn.microsoft.com/en-us/library/szcefbbd(v=vs.110).aspx) instead of `Form.Hide(w)`? If so, could you [edit] your question to clarify? – dbc Jan 06 '18 at 22:09