问题描述
我有一个股票dataFeed,该事件每秒触发大约4或5次事件,通过事件arg发送股票数据.我解析事件arg,然后通过写入的数据库对象将结果插入数据库.所有这些活动似乎使Windows窗体不堪重负,并消耗了大部分系统资源.我想将stock dataFeed事件放在一个线程上,但我不知道如何.我尝试创建ThreadStart对象,并使用匿名委托将事件传递给,但是我不知道如何实例化事件arg或要传递的对象...
例如:
Hi,
I have a stock dataFeed that has an event that fires approx 4 or 5 times per sec sending the stock data via a event arg. I parse the event arg and insert the results into a database via a database object that wrote. All of this activity seems to overwhelm the windows form and consumes most of system resources. I''d like to put the stock dataFeed event on a thread but I don''t know how. I''ve tried creating a ThreadStart object and using an anonymous delegate to pass the event to but I dont know how to instantiate the event arg or what object to pass...
example:
// dataFeed event
private void stockDataFeed(object sender, stockDataFeedArg arg)
{
myDatabaseOject.Insert(arg.stockPrice);
}
private void Button_Click(object sender, EventArgs e)
{
ThreadStart tS = delegate() {stockDataFeed(?,?);};
Thread t = new Thread(tS);
t.Start();
}
能否有人请向我解释/告诉我我做错了什么以及解决该问题的正确方法是什么.
谢谢!
-Donald
Can some one please explain/show me what I''m doing wrong and what''s the correct way to go about this.
Thanks!
-Donald
推荐答案
这篇关于如何将事件传递给线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!