English 中文(简体)
如何向桌面应用发出推动通知书
原标题:How to send a push notification to desktop application
  • 时间:2012-05-11 23:56:46
  •  标签:
  • c#

I have an application which resides in the system tray, and instead of the standard polling method (check the server at X sec interval for updates) I wish to use a push notification system. So when there s an update, all clients will receive a message and they will do their task. The webserver will be Debian with Apache and PHP.

我的目标平台是www.NET 3.5,因此如何做到这一点? <代码>观察员设计模式不适用(因为其为4.0或更高)。

最佳回答

You have to create two interfaces and their derived concrete classes. Your service will create IObservable, IObserver and ApplicationErrorState.

你的客户将创建班级,并从我观察员那里获得ErrorMessageSync。

Here is my example which displays errors and is created with .Net 3.5.

www.un.org/spanish/ecosoc P.S. 也可使用代表<>。

/// It will store observers and will push the message
public interface IErrorObservable
{
  void Attach(IErrorObserver observer);

  void Detach(IErrorObserver observer);

  void Notify();
}

public interface IErrorObserver
{
  void Update(string message);
}

///It is concrete class to push message
public sealed class ApplicationErrorState : IErrorObservable
{
  private List<IErrorObserver> _observers = new List<IErrorObserver>();
 
  ///constructor
  public ApplicationErrorState()
  {
  }

  public void Attach(IErrorObserver observer)
  {
     _observers.Add(observer);
  }

  public void Detach(IErrorObserver observer)
  {
     _observers.Remove(observer);
  }

  public void Notify()
  {
     foreach (IErrorObserver observer in _observers)
     {
        observer.Update(/*Logic*/);
     }
  }

  public void SetError()
  {
     Notify();
  }


  ///COncrete subject 
  private class ErrorMessageSync : IErrorObserver
  {
     private MyClass _parent;
     
     public ErrorMessageSync(MyClass parent)
     {
        _parent = parent;
     }

     public void Update(string message)
     {
            //This work will be done
     }
  }

这种方法就是UML。

“Check

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签