哪个异步。我应该使用模式吗? [英] Which Async. Pattern should I be using?

查看:77
本文介绍了哪个异步。我应该使用模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个监控员工状态的窗体[位置/工作

状态等]它每2秒轮询一次数据库以获取更新[索引on

带有''LastUpdate''日期时间字段的历史记录表,然后使用Invoke更新绑定到网格的基础

数据集,以编组到gui线程。


我现在应该使用什么模式我正在升级到.net 2.0? APM,async

委托和BeginInvoke或Thread.Start等...?

我应该创建一个单独的线程(或使用线程池)和

使用Thread.Sleep(2000)在内部循环上设置轮询?


对于我应该采取什么方法的任何建议都将非常感激。


非常感谢,

Graeme。

I''ve got a windows form that monitors the status of employees [location/work
status etc] it polls a database every 2 seconds to fetch updates [index on
history table with ''LastUpdate'' Datetime field] then update a underlying
dataset bound to a grid using Invoke to marshal to the gui thread.

What pattern should I be using now I''m upgrading to .net 2.0? APM, async
delegates and BeginInvoke or Thread.Start etc...?

Should I be creating a single thread manulally (or using threadpool) and and
setting the polling on an internal loop with a Thread.Sleep(2000) ?

Any advice on what approach I should take would be very much appreciated.

Many thanks,
Graeme.

推荐答案

你可以用一个System.Timers.Timer在一个线程上触发Elasped事件

池线程。在事件处理程序开始时,停止计时器,然后执行

工作,重新启动计时器。


你仍然需要调用它在池线程上触发的UI线程。


HTH


-

Ciaran O''' 'Donnell
http://wannabedeveloper.spaces.live.com

" Dog Ears"写道:
You could use a System.Timers.Timer which fires the Elasped event on a thread
pool thread. At the start of the event handler, stop the timer, then do the
work, the restart the timer.

You would still need to invoke to the UI thread as it fires on a pool thread.

HTH

--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"Dog Ears" wrote:

我有一个窗体,监控员工的状态[位置/工作

状态等]它民意调查数据库每2秒获取一次更新[

历史表上的索引,带有''LastUpdate''日期时间字段],然后使用Invoke to marshal更新绑定到网格的基础

数据集到了gui线程。


我现在应该使用什么模式我正在升级到.net 2.0? APM,async

委托和BeginInvoke或Thread.Start等...?

我应该创建一个单独的线程(或使用线程池)和

使用Thread.Sleep(2000)在内部循环上设置轮询?


对于我应该采取什么方法的任何建议都将非常感激。


非常感谢,

Graeme。
I''ve got a windows form that monitors the status of employees [location/work
status etc] it polls a database every 2 seconds to fetch updates [index on
history table with ''LastUpdate'' Datetime field] then update a underlying
dataset bound to a grid using Invoke to marshal to the gui thread.

What pattern should I be using now I''m upgrading to .net 2.0? APM, async
delegates and BeginInvoke or Thread.Start etc...?

Should I be creating a single thread manulally (or using threadpool) and and
setting the polling on an internal loop with a Thread.Sleep(2000) ?

Any advice on what approach I should take would be very much appreciated.

Many thanks,
Graeme.


非常感谢您的回复,正如我发布的那样,我在计时器上磕了一下

级(CLR通过C#,J.Richter)它确实是一个不错的选择...


但我的唯一值得关注的是,大多数异步代码/逻辑等目前都处于形式中,我想将其封装到监控中。类,所以它b / b
执行异步更新''内部''我只是有点担心

更新。也许这会使设计复杂化?


问候,

Graeme。

" Ciaran O''''Donnell" < Ci ************ @ discussion.microsoft.com写在

消息新闻:10 **************** ****************** @ microsof t.com ...
Many thanks for your reply, just as I posted I stumbed across the timer
class (CLR via C#, J.Richter) it does seem a good option...

But my only concern is that most of the async code/logic etc is currently in
the form, i''d like to encapsulate it into the "monitoring" class, so that it
performs the asynchronous update ''internally'' i''m just a bit concerned about
the updates. Maybe this would over complicate the design?

Regards,
Graeme.
"Ciaran O''''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:10**********************************@microsof t.com...

您可以使用System.Timers。计时器在

线程上触发Elasped事件

池线程。在事件处理程序开始时,停止计时器,然后执行



工作,重新启动计时器。


您仍然需要调用UI线程,因为它在池上触发

线程。


HTH


-

Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com



如果我有一个由另一个线程和一个Gui更新的集合

控件(网格)绑定到该集合,如何从其他线程更新集合

,因为集合没有''InvokeRequired' '

属性,我只需要专注于同步而不用担心

关于''调用''到gui线程?

" ;狗耳朵 < gr ********* @ reverse.net.virginwrote in message

新闻:MK ******************* ** @ pipex.net ...
If i have a collection that is being updated by another thread, and a Gui
control (grid) is bound to that collection, how do i update the collection
from the other thread, as the collection hasn''t got an ''InvokeRequired''
property, do i just need to concentrate on Synchronisation and not worry
about ''invoke'' to the gui thread?
"Dog Ears" <gr*********@reverse.net.virginwrote in message
news:MK*********************@pipex.net...

非常感谢您的回复,就像我发布的那样,我在计时器上磕了一下

class( CLR通过C#,J.Richter)它似乎是一个不错的选择...


但我唯一担心的是大多数异步代码/逻辑等目前是
$表格中的b $ b,我想将其封装到监控中。类,所以

它执行异步更新''内部''我只是有点

关注更新。也许这会使设计复杂化?


问候,

Graeme。


Ciaran O '' 唐奈" < Ci ************ @ discussion.microsoft.com写在

消息新闻:10 **************** ****************** @ microsof t.com ...
Many thanks for your reply, just as I posted I stumbed across the timer
class (CLR via C#, J.Richter) it does seem a good option...

But my only concern is that most of the async code/logic etc is currently
in the form, i''d like to encapsulate it into the "monitoring" class, so
that it performs the asynchronous update ''internally'' i''m just a bit
concerned about the updates. Maybe this would over complicate the design?

Regards,
Graeme.
"Ciaran O''''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:10**********************************@microsof t.com...

>您可以使用系统。 Timers.Timer在一个
线程的池线程中触发Elasped事件。在事件处理程序开始时,停止计时器,然后执行
工作,重新启动计时器。

你仍然需要调用UI线程,因为它在游泳池火上
线程。

HTH

- Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com




这篇关于哪个异步。我应该使用模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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