C#多线程函数如何传参数
Threadth=newThread(newThreadStart(DownLoad));th.IsBackground=true;th.Start();privatev...
Thread th = new Thread(new ThreadStart(DownLoad));
th.IsBackground = true;
th.Start();
private void DownLoad(){ }
我现在想让委托实现参数的传递,就是:
private void DownLoad(string str){ }
如何实现呢。我有找到一个解决方法是:
MyDelegate dele = new MyDelegate (DownLoad);
DownLoad.BeginInvoke("abcd");
可是我没解决掉,有谁知道的帮帮我 。在这里多谢拉。 展开
th.IsBackground = true;
th.Start();
private void DownLoad(){ }
我现在想让委托实现参数的传递,就是:
private void DownLoad(string str){ }
如何实现呢。我有找到一个解决方法是:
MyDelegate dele = new MyDelegate (DownLoad);
DownLoad.BeginInvoke("abcd");
可是我没解决掉,有谁知道的帮帮我 。在这里多谢拉。 展开
1个回答
2013-08-29
展开全部
你那个方法我没怎么用过 这个是我写的一个程序中线程的创建
struct myarg{
U32 *fd;
U32 *fd_id;
U32 *qsend_msgid,*qrecv_msgid;
struct my_msg_st *qsend_data;
struct my_msg_st *qrecv_data;
};
main()
{
pthread_t tidp_init,tidp_read,tidp_write;
my_arg.fd = fd;
my_arg.qrecv_msgid = &recv_msgid;
my_arg.qsend_msgid = &send_msgid;
if(pthread_create(&tidp_init,NULL,thread_fun_date,&my_arg) != 0)
{
printf("thread_fun_init is over !\n");
}
if(pthread_create(&tidp_read,NULL,thread_fun_read,&my_arg) != 0)
{
printf("thread_fun_read is over !\n");
}
if(pthread_create(&tidp_write,NULL,thread_fun_write,&my_arg) != 0)
{
printf("thread_fun_write is over !\n");
}
}
void*thread_fun_read(void * my_arg)
{
printf("!!!!!!! thread_fun_read !!!!!!!!!!!!\n");
U32 i;
pthread_t tidp;
struct myarg *p_my_arg,fd_myarg[UART_NUM];
p_my_arg = (struct myarg *)my_arg;
}
struct myarg{
U32 *fd;
U32 *fd_id;
U32 *qsend_msgid,*qrecv_msgid;
struct my_msg_st *qsend_data;
struct my_msg_st *qrecv_data;
};
main()
{
pthread_t tidp_init,tidp_read,tidp_write;
my_arg.fd = fd;
my_arg.qrecv_msgid = &recv_msgid;
my_arg.qsend_msgid = &send_msgid;
if(pthread_create(&tidp_init,NULL,thread_fun_date,&my_arg) != 0)
{
printf("thread_fun_init is over !\n");
}
if(pthread_create(&tidp_read,NULL,thread_fun_read,&my_arg) != 0)
{
printf("thread_fun_read is over !\n");
}
if(pthread_create(&tidp_write,NULL,thread_fun_write,&my_arg) != 0)
{
printf("thread_fun_write is over !\n");
}
}
void*thread_fun_read(void * my_arg)
{
printf("!!!!!!! thread_fun_read !!!!!!!!!!!!\n");
U32 i;
pthread_t tidp;
struct myarg *p_my_arg,fd_myarg[UART_NUM];
p_my_arg = (struct myarg *)my_arg;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询