方法1:

ParameterizedThreadStart 委托+Thread.Start 方法 (Object)

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            ////Start the update check procedure.
            string ssid = this.txtSSID.Text;
            string username = this.txtName.Text;
            string password = this.txtPassword.Text;
//ParameterizedThreadStart 委托
            Thread loginThread = new Thread(new ParameterizedThreadStart(toLogin));
//Thread.Start 方法 (Object)
            loginThread.Start(ssid + "," + username + "," + password);
        }         private void toLogin(object parameters)
        {
            try
            {
                string p = parameters as string;
                string s = ",";
                string[] name = p.Split(s.ToCharArray());
                string ssid = name[0];
                string username = name[1];
                string password = name[2];
                int errorCode = roaming_instance.Login(ssid, username, password);
                Debug.WriteLine("login error code:" + errorCode);
                if (AicentErrorCode.AICENT_OK == errorCode)
                {
                    //login ok
                    //add your code
                }
                else
                {
                    //failed to login
                    //add your code
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Assert failed as login error code not match:" + ex);
            }
        }

方法2:

ThreadStart 委托+实例对象方法

using System;
using System.Threading; class Test
{
static void Main()
{
// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ThreadStart delegate. Beginning in version
// 2.0 of the .NET Framework, the explicit delegate is not
// required.
//
Work w = new Work();
w.Data = 42;
//ThreadStart 委托
  threadDelegate = new ThreadStart(w.DoMoreWork);
newThread = new Thread(threadDelegate);
newThread.Start();
}
} class Work
{
public int Data;
//实例对象方法
public void DoMoreWork()
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}
} /* This code example produces the following output (the order
of the lines might vary): Instance thread procedure. Data=42
*/

C#中给线程传值并启动的更多相关文章

  1. Java并发1——线程创建、启动、生命周期与线程控制

    内容提要: 线程与进程 为什么要使用多线程/进程?线程与进程的区别?线程对比进程的优势?Java中有多进程吗? 线程的创建与启动 线程的创建有哪几种方式?它们之间有什么区别? 线程的生命周期与线程控制 ...

  2. android中的线程池学习笔记

    阅读书籍: Android开发艺术探索 Android开发进阶从小工到专家 对线程池原理的简单理解: 创建多个线程并且进行管理,提交的任务会被线程池指派给其中的线程进行执行,通过线程池的统一调度和管理 ...

  3. C#中的线程(一)入门

    文章系参考转载,英文原文网址请参考:http://www.albahari.com/threading/ 作者 Joseph Albahari,  翻译 Swanky Wu 中文翻译作者把原文放在了& ...

  4. C#中的线程四(System.Threading.Thread)

    C#中的线程四(System.Threading.Thread) 1.最简单的多线程调用 System.Threading.Thread类构造方法接受一个ThreadStart委托,改委托不带参数,无 ...

  5. 浅谈Excel开发:十 Excel 开发中与线程相关的若干问题

    采用VSTO或者Shared Add-in等技术开发Excel插件,其实是在与Excel提供的API在打交道,Excel本身的组件大多数都是COM组件,也就是说通过Excel PIA来与COM进行交互 ...

  6. 查看JAVA进程中哪个线程CPU消耗最高

    一,在centos linux 上查看进程占用cpu过高 top  shift+h 查看哪个进程程消耗最高     二,查看JAVA进程中哪个线程消耗最高   2.1 导出java运行的线程信息   ...

  7. Java中的线程

    http://hi.baidu.com/ochzqvztdbabcir/item/ab9758f9cfab6a5ac9f337d4 相濡以沫 Java语法总结 - 线程 一 提到线程好像是件很麻烦很复 ...

  8. Windows API学习---用户方式中的线程同步

    前言 当所有的线程在互相之间不需要进行通信的情况下就能够顺利地运行时, Micrsoft Windows的运行性能最好.但是,线程很少能够在所有的时间都独立地进行操作.通常情况下,要生成一些线程来处理 ...

  9. Java多线程——<二>将任务交给线程,线程声明及启动

    一.任务和线程 <thinking in java>中专门有一小节中对线程和任务两个概念进行了具体的区分,这也恰好说明任务和线程是有区别的. 正如前文所提到的,任务只是一段代码,一段要达成 ...

随机推荐

  1. 记一次 java程序优化

    优化原因 环境中部署两个程序: web应用 tomcat   10G(webservice服务端,前端web服务) java应用               5G(webservice客户端,sock ...

  2. 【转】Android下编译jni库的二种方法(含示例)

    原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...

  3. unix c 04

      系统调用(System Call)   文件的操作函数(Unix/Liunx系统内部提供的函数)   time 可以查看程序的运行时间,包括用户层时间和系统层的时间.   系统调用其实就是一系列的 ...

  4. Spiral Matrix 解答

    Question Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ...

  5. android滑动基础篇 - 触屏显示信息

    效果图: 代码部分: activity类代码: package com.TouchView; /* * android滑动基础篇 * */ import android.app.Activity; i ...

  6. cookielib模块基础学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' import cookielib #主要用于处理http客户端的co ...

  7. CRC 模式及实现

    CRC : Cyclic redundancy Check 循环冗余校验 概述参见wiki百科:http://en.wikipedia.org/wiki/Cyclic_redundancy_check ...

  8. 訪问远程WAMP 下phpmyadmin

    WAMP环境是一个非常优秀的webservice集成环境,它集成的phpmyadmin也是一款非常优秀的数据库訪问软件.wamp默认安装下,phpmyadmin工具仅仅能本地用,在站点开发中,数据库都 ...

  9. ThinkPHP整合百度Ueditor图文教程

    ThinkPHP整合百度Ueditor图文教程 ThinkPHP整合百度Ueditor,基于黄永成老师的视频说明的申明:最好大家都能写绝对路径的都写好绝对路径比如:window.UEDITOR_HOM ...

  10. jquery mouseout和mouseleave区别

    mouseout()和mouseleave() 都是鼠标移出元素时触发,但是这两者又有所区别,需要大家留意: 不论鼠标指针离开指定元素还是该元素子元素,都会触发 mouseout 事件. 只有在鼠标指 ...