CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Sep 2010
    Posts
    35

    Problem calling a method of an object maded in a thread.

    Hi guys.

    All in FORM1

    Code:
    public partial class Form1 : Form
        {  
    Thread thread;
     
    public Form1()
            {
    thread = new Thread(run);
                thread.Start();   
            }
    public void run()
            {
              ConectadoThread socketConectado = new ConectadoThread(); 
            }
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
     
            {    
     
                socketConectado.close();
     
            }
     
     }
    Why when i do "socketConectado.close()" it shows me:


    Error 2 The name 'socketConectado' does not exist in the current context C:\Users\Mauri\Desktop\Proyectos\Visual Studio 2008\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs
    Thanks =)

    Edit: Solved, need to define the object outside the run method
    Last edited by krosty4782; December 15th, 2010 at 10:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured