PDA

View Full Version : حرفه ای: Refresh اطلاعات برنامه Monitoring با ایجاد هر تغییر در Database



Nima_kyan
شنبه 07 اردیبهشت 1392, 14:03 عصر
سلام
دوستان در سیستم های مانیتورینگ چطور میشه به روز شدن اطلاعات برنامه رو بر پایه ایجاد هر تراکنش در بانک اطلاعاتی قرار داد؟؟؟
(به جای استفاده از Timer که معایب خاص خودش رو داره)

tooraj_azizi_1035
شنبه 07 اردیبهشت 1392, 14:22 عصر
باید از کلاس SqlDependency استفاده کنید:http://msdn.microsoft.com/en-us/library/a52dhwx7(v=vs.80).aspx

NasimBamdad
شنبه 07 اردیبهشت 1392, 14:23 عصر
از Thread می تونی استفاده کنید . بهتره .

Nima_kyan
شنبه 07 اردیبهشت 1392, 17:09 عصر
باید از کلاس SqlDependency استفاده کنید:http://msdn.microsoft.com/en-us/library/a52dhwx7(v=vs.80).aspx
ممنون.
اون مطلب رو خوندم. ولی یه بخش هایی ازش مبهم هستش. به خصوص بند 12
In order to receive notifications when data on the server changes, the application needs an event handler that matches the signature of the OnChangeEventHandler (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.onchangeeventhandler%28v=vs. 80%29.aspx) delegate. The procedure needs to catch the event and switch from the worker thread to the UI thread. Add the following code to the form's module:



private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
// This event will occur on a thread pool thread.
// Updating the UI from a worker thread is not permitted.
// The following code checks to see if it is safe to
// update the UI.
ISynchronizeInvoke i = (ISynchronizeInvoke)this;

// If InvokeRequired returns True, the code
// is executing on a worker thread.
if (i.InvokeRequired)
{
// Create a delegate to perform the thread switch.
OnChangeEventHandler tempDelegate =
new OnChangeEventHandler(dependency_OnChange);

object[] args = { sender, e };

// Marshal the data from the worker thread
// to the UI thread.
i.BeginInvoke(tempDelegate, args);

return;
}

Nima_kyan
شنبه 07 اردیبهشت 1392, 17:19 عصر
از Thread می تونی استفاده کنید . بهتره .
به چه شکلی؟

Mahmoud.Afrad
شنبه 07 اردیبهشت 1392, 18:27 عصر
تایمر و thread رو بیخیال شو.


ممنون.
اون مطلب رو خوندم. ولی یه بخش هایی ازش مبهم هستش. به خصوص بند 12
In order to receive notifications when data on the server changes, the application needs an event handler that matches the signature of the OnChangeEventHandler (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.onchangeeventhandler%28v=vs. 80%29.aspx) delegate. The procedure needs to catch the event and switch from the worker thread to the UI thread. Add the following code to the form's module:

چیش مبهمه. این رویدادی هست که در صورت تغییر در دیتابیس Raise میشه. منتها چون این رویداد روی ترد UI نیست باید از طریق دلیگیت این متد رو دوباره فراخوانی کرد.

mousa1992
شنبه 07 اردیبهشت 1392, 18:44 عصر
سلام
برنامه ای رو آقای علی حبیبی توی همین سایت قرار دادن براتون میفرستم از SqlDependency استفاده کرده و میتونید انالیزش کنید ( برنامه چت با استفاده از دیتابیس sql هست)

موفق باشید

Nima_kyan
یک شنبه 08 اردیبهشت 1392, 10:28 صبح
با تشکر از همه دوستان،
من روی یکی از مراکز تست کردم اوکی بود.
حالا میخوام به صورت همزمان روی مراکز زیادی تست کنم(سراسر کشور).
یعنی به صورت همزمان به همشون ping کنم.
ورژن قبلی نرم افزار بنا به درخواست خودشون با استفاده از حلقه پیاده سازی شده بود و یکی یکی به مراکز وصل میشد ولی حالا میخوان همزمان مانیتور بشن.
آیا این قسمت رو باید با MutiTreading انجام بدم؟؟

h_assefi
یک شنبه 08 اردیبهشت 1392, 15:42 عصر
سلام
به نظر من شما باید از همون تکنیک Treading استفاده کنی
چون از منابع سخت افزاری به صورت بهینه تر استفاده میشه
موفق باشید