使用C#进行多线程数据库操作(需要帮助!) [英] multi-threading database operations with C# (need help!)

查看:1499
本文介绍了使用C#进行多线程数据库操作(需要帮助!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在同一主题上发布了一些主题,我得到了一些非常好的帮助,但我只是一个新手开发人员,我很难理解主题.我有一个实时库存dataFeed,每秒可发出2或3条消息.我正在尝试解析供稿,并将结果插入一个表中,然后使用结果来更新另一个表.这是我正在做的事的一个例子:



I''ve posted a couple threads on this same subject and I''ve gotten some really good help but I''m just a novice dev and I''m having a VERY hard time getting my hand around threading! I have a real-time stock dataFeed that''s firing off 2 or 3 messages per/sec. I''m trying parse the feed and insert the results in one table and use the results to update another table. Here''s an example of what I''m doing:

MyDatabaseClass myDatabaseObj = new MyDatabaseClass();

// dataFeed eventHandler
private void (object sender, stockQuoteEvent e)
{
   // I'm parsing the feed...
   string[] stockData = e.Quote.Split(',');
   double bidPrice = stockData[0];
   double askPrice = stockData[1];
   double lastPrice = stockData[4];
   int volume = stockData[10];
   
   // shouldn't these two object methods be ran on their own
   // threads? If so I can't pass them to ParameterizedThreadStart
  // delegate because they both have more than one parameter...
   myDatabase.Insert(bidPrice,askPrice,lastPrice,volume);
   myDatabase.Update(bidPrice,askPrice,lastPrice,volume);
}



当我运行此代码时,UI变得无响应,CPU使用率猛增到60%-70%!并且当客户端应用程序查询dbServer时,它滞后了很大的时间!

能否请一个人用相对简单的例子和​​解释来解释/显示我该如何去做?我确实尝试学习并掌握了相关知识,但我只需要带有清晰说明的示例

提前谢谢!
-Donald



When I run this code the UI becomes unresponsive and CPU usage skyrockets to 60%-70%! and when the client app queries the dbServer it''s lagging BIG time!

Can some one PLEASE explain/show me how to go about this with relatively simple examples and explanations? I really trying to learn and get a handle on this but I just need examples with clear explanations

Thanks in advance!
-Donald

推荐答案

This[^] page on MSDN might help you. Scroll down to the section on passing data to threads.


这篇关于使用C#进行多线程数据库操作(需要帮助!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆