解决方案 »

  1.   

    我想知道怎么让form2 show出来
      

  2.   

    这是socket服务器端代码,用到了其他线程,但也不至于会让form show 不出来把
      

  3.   

    用调试器(OD,WINDBG等)调试服务程序
    To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ProgramName
    The ProgramName is the image file for the service application you are debugging. Do not specify a path. For example, the ProgramName might look like MyService.exe.Under this key create a string data value called Debugger. The value of this string should be set to the full path of the debugger that will be used. For example,c:\Debuggers\windbg.exeIn addition to setting this registry key, the service application must be ed as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop.This again requires modifying a registry key: you must bitwise-or the type entry for your service with 0x100 (this is the value for SERVICE_INTERACTIVE_PROCESS according to Winnt.h). The exact location and name of this registry entry varies. For example:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceKey
    Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting. Adjusting the timeout involves setting an entry in the following registry key:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
    Under this key, create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that you want the service to wait before timing out. For example, 60,000 is one minute, while 86,400,000 is 24 hours.设置ServicesPipeTimeout后需要重启系统才生效Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.)If your service is running with other services in a Service Host Process, you may need to isolate the service into its own Service Host Process.
      

  4.   

    创建、显示、设置与界面控件必须在主线程,否则必死无疑。说实在,没有随机死是比较客气的。
            private void SuccessfulConnection(object obj)
            {
                try
                {
                    userserver = new UserServer((TcpClient)obj);
                }
                catch
                {
                }
                this.Invoke(appendstringdelegate1, "1");
                Action show = new Action(showWin);
                Application.OpenForms[0].Invoke(show);
            }
            void showWin
            {
                formwaitingroomS = new FormWaitingRoom();
                formwaitingroomS.Show();
            }
      

  5.   

    Application.Run(formwaitingroomS );
      

  6.   

    ---1---            this.Invoke(appendstringdelegate1, "1");//一个代理,运行正常,用于执行this.Hide(),执行到这里,form1正常隐藏
     
                //执行到这里,生成一个vshost32.exe的神奇文件,文件的icon是那种出错文件的icon,调试的时候看不了长什么样
     
    ---2---            formwaitingroomS = new FormWaitingRoom();//问题就出在这两行诡异的地方,实例化已经声明的变量(我已经在程序前面声明过此变量)
     
     
    ---3---            formwaitingroomS.Show();//此句不解释
       
                //好了,那个form2执行到这里直接消失!!!!!!然后程序就到这里不动了!!!!!!我都不知道程序在干神马!后面没代码了,它就卡在这里,form1隐藏了,form2诡异消失,也就是没有窗口显现,但是通过调试,我知道程序还在执行,不知道它在执行什么东西!
     ------------------------------------------
    在---1---里面知道用invoke,为什么下面就忘记了
    把2,3也通过invoke放到主线程去执行就OK了直观感觉,你的逻辑也有点问题,每建立一个链接就打开一个窗口?