Threading in C#

Hello Everyone,

I have a tab application, which initially I made single threaded....I added a dll which has a form. Now when I change to a tab method in that dll gets fired and form comes up, which makes everything else unresponsive....

Whats the best solution to implement thread to solve that problem....

Secondly, I tried doing something this way.....

namespace something

{

public partial class Some : Form

{

public Some()

{

}

// Then here more procedures

}

// Here I created another class which fires the method from dll....

public partial class Test

{

public DLLFire()

{

}

}

Now If i do something along these lines....to start the thread

Thread test = new Thread(new ThreadStart(DLLFire()));

it says Method name expected.....I add these lines in some class to run from there....

I was wondering the best solution and what I'm doing wrong here....

Thanks, for the help..

Harsimrat



Answer this question

Threading in C#

  • Shawn O

    You said that, when you change to a tab method in that dll gets fired and form comes up, which makes everything else unresponsive....

    I think you are showing Form using ShowDialog(), in which the new form opened got the focused and all the other forms stop responding unitl you close the focued form.




  • Tim Benton

    I have other forms which doesnt come from dll, have no problem I can run them as showdialog and they are absolutely fine....

    I wish I can send you picture.....it doesnt let me put here

    Can you tell me how can I say enabled = false.....


  • Andy Everett

    It stays accessible because you run in other thread. You can try to disable it by setting Enabled = false, but I think you need to find the source of your problem - why your form it badly updated.

    ShowDialog() can be called ShowDialog(this) - check this out.



  • Julesy

    nice..


  • Frent

    As far as i understand, u have a FormA, which has a Tab Control on it, now you have a DLL that contains FormB, whenever you move thorugh the tab, you want that on each Tab Click, you show the FormB. Then why are you using threads...... when you don;t want modeless forms


  • Wanel

    Its a C++ .NET dll...

    this is what I do there to display the form..

    // Get the Form Instance

    RIM_USBClient::UserPassvalidation uValid;

    // Update some form stuff

    uValid.label4->Text = BBPIN->ToString();

    uValid.label5->Text = pAttempts->ToString();

    // Show Dialog

    uValid.ShowDialog();


  • SriramY

    Hello,

    Putting in seperate thread solved that problem...but now when the other form comes up I can still play with other tabs which I want to block until I get the feedback from that form.....


  • Balsoft

    Error 1 error C2664: 'System::Windows::Forms::DialogResult System::Windows::Forms::Form::ShowDialog(System::Windows::Forms::IWin32Window ^)' : cannot convert parameter 1 from 'RIM_USBClient::USBClient ^const ' to 'System::Windows::Forms::IWin32Window ^'

    ShowDialog(this) doesn't work....


  • schwabbie

    Try this

    Thread test = new Thread(new ThreadStart(DLLFire));




  • KPeters

    Hi!

    Do you really need threading

    What code makes your form so slow You make computations there If yes - threading is good for you. Working with forms in multiple threads (mixing UI without proper synchronization) can make you problems, so try to avoid this.

    Also you can run things in other thread much easier:

    new MethodInvoker(delegate

    {

    // any code here will be run in separate background thread

    BeginInvoke(new MethodInvoker(delegate

    {

    // any code here will be run again in UI thread (thread where is form are running)

    }));

    }).BeginInvoke(null, null);



  • Jeremy Vianna

    hello,

    in the tab when I click say second day the form b from dll gets fired...and I have that as showDialog() what it does is if i try to move that form around it doesnt repaint it that well....and it leaves it trails back when it is closed and say after the form is closed a message box comes up from that same dll it has same problems....

    that was the reason I thought should do using Thread, as Its seperate and doesn't depend on anything.....


  • tyacko

    If your form do not repaint at all - there is some problem. Actually it's strange, if your UI thread locks - then how popup form works

    If your form repaint incorrectly - there is problem in that form's painting (any custom controls on it ).

     

    Can you post code how you create and call popup form from other assembly



  • Il-Sung Lee - MSFT

    Hello Ali,

    Yes, I'm doing showdialog() as I don't want the User to do anything else until he/she gives me response from the Form.....Even the new opened form you move quickly it doesnt repaint it well.....So i thought threading should solve this problem...

    I tried the way you told and even zapacila89's way still I can't get it to work same error....Method name expected....


  • David Reeves

    Sorry, my fault Ali's solution work...

    Thanks Ali..

    If you can guide me to have the forms responsive.....

    Harsimrat


  • Threading in C#