大家好!遇到这么一个问题!
我想在填写了一张定单后通知所有的跟单人员。我现在一个listbox上选择接受的用户,然后添加到一个datagrid中,最后,我想按一个按钮,然后将这个信息(“定单一已完成!”)发送到网络内的选定人员的机器上(datagrid中的用户)。该如何实现啊??谢谢!最好是有代码!
我想在填写了一张定单后通知所有的跟单人员。我现在一个listbox上选择接受的用户,然后添加到一个datagrid中,最后,我想按一个按钮,然后将这个信息(“定单一已完成!”)发送到网络内的选定人员的机器上(datagrid中的用户)。该如何实现啊??谢谢!最好是有代码!
解决方案 »
- C#怎么跳出timer1_Tick循环
- 由于缺少调试目标,....使其指向目标程序集的正确位置 各位大侠求帮助 十万火急
- C#线性表的插入问题,向高手请教!(例子为向数组中插入一个数)
- 我使用XP SP3安装IIS找不到安装组件选项是为什么?
- 什么是算法?
- sql2000, 表aaa和表bbb结构相同,如何将bbb中和aaa主键值不同的纪录插入aaa?
- 请问如何在DataGrid控件中显示复选框?
- .net连接Oracle的问题
- .net中EF框架里的删除语句怎么写
- C#的问题:请问VC中的 hbitmap 在C#中如何写呢?(小女子刚刚开始学习这门,请各位大侠多多帮忙...)
- sockets通信问题??(100分)
- (急)用XmlDocument类的load方法打开的文件如何关闭?
定时刷新最好了,要是自己用SOCKET进行连接的话,好累
/*=====================================================================
File: Chat.cs Summary: Demonstrates how to use delegates and events.---------------------------------------------------------------------
This file is part of the Microsoft .NET Framework SDK Code Samples. Copyright (C) Microsoft Corporation. All rights reserved.This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation. See these other
materials for detailed information regarding Microsoft code samples.THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
=====================================================================*/// Add the classes in the following namespaces to our namespace
using System;
///////////////////////////////////////////////////////////////////////////////
class DChatServer {
// Declare a multicast delegate type
public delegate void OnMsgArrived(String message); // Declare a reference to an OnGetString delegate
private static OnMsgArrived onMsgArrived; // Private to prevent instances of this type from being instantiated.
private DChatServer() {} // This function is necessary because we are not using an event
public static void ClientConnect(OnMsgArrived onMsgArrived) {
DChatServer.onMsgArrived = (OnMsgArrived)
Delegate.Combine(DChatServer.onMsgArrived, onMsgArrived);
} // This function is necessary because we are not using an event
public static void ClientDisconnect(OnMsgArrived onMsgArrived) {
DChatServer.onMsgArrived = (OnMsgArrived)
Delegate.Remove(DChatServer.onMsgArrived, onMsgArrived);
} public static void SendMsg(String msg) {
// Send message to ALL clients
SendMsg(msg, null);
} public static void SendMsg(String msg, Object excludeClient) {
// Send message to all clients except 'excludeClient'
if (excludeClient == null) {
onMsgArrived(msg);
} else {
Delegate[] DelegateList = onMsgArrived.GetInvocationList();
for (int i = 0; i < DelegateList.Length; i++) {
if (DelegateList[i].Target != excludeClient) {
((OnMsgArrived) DelegateList[i])(msg);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
class DChatClient {
private void onMsgArrived(String msg) {
Console.WriteLine("Msg arrived (Client {0}): {1}", clientName, msg);
} private String clientName; public DChatClient(String clientName) {
this.clientName = clientName;
DChatServer.ClientConnect(new DChatServer.OnMsgArrived(onMsgArrived));
} public void Dispose() {
DChatServer.ClientDisconnect(new DChatServer.OnMsgArrived(onMsgArrived));
GC.SuppressFinalize(this);
} ~DChatClient() {
Dispose();
}
}
///////////////////////////////////////////////////////////////////////////////
class EChatServer {
// Declare a multicast (because return type is void) delegate type
public delegate void OnMsgArrived(String message); // Declaring an event causes the compiler to generate a PRIVATE field
// (onMsgArrived) that references the tail of an OnMsgArrived delegate
// linked-list. The compiler also generates two PUBLIC methods,
// add_onMsgArrived and remove_onMsgArrived which are called when the
// += and -= operators are applied to the event's delegate.
public static event OnMsgArrived onMsgArrived; // Private to prevent instances of this type from being instantiated.
private EChatServer() {} public static void SendMsg(String msg) {
// Send message to ALL clients
SendMsg(msg, null);
} public static void SendMsg(String msg, Object excludeClient) {
// Send message to all clients except 'excludeClient'
if (excludeClient == null) {
onMsgArrived(msg);
} else {
Delegate[] DelegateList = onMsgArrived.GetInvocationList();
for (int i = 0; i < DelegateList.Length; i++) {
if (DelegateList[i].Target != excludeClient) {
((OnMsgArrived) DelegateList[i])(msg);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
class EChatClient {
private void onMsgArrived(String msg) {
Console.WriteLine("Msg arrived (Client {0}): {1}", clientName, msg);
} private String clientName; public EChatClient(String clientName) {
this.clientName = clientName;
EChatServer.onMsgArrived += new EChatServer.OnMsgArrived(onMsgArrived);
} public void Dispose() {
EChatServer.onMsgArrived -= new EChatServer.OnMsgArrived(onMsgArrived);
GC.SuppressFinalize(this);
} ~EChatClient() {
Dispose();
}
}
///////////////////////////////////////////////////////////////////////////////
class Application {
private static void DelegateChatServerDemo() {
Console.WriteLine("Demo start: Delegate Chat Server."); DChatClient cc1 = new DChatClient("1");
DChatClient cc2 = new DChatClient("2");
DChatClient cc3 = new DChatClient("3"); DChatServer.SendMsg("Hi to all clients");
DChatServer.SendMsg("Hi to all clients except client 2", cc2); // Explicitly disconnect the clients from the chat server.
// If we didn't do this, the clients' memory could not be
// reclaimed until the server is collected (app shutdown time).
cc1.Dispose();
cc2.Dispose();
cc3.Dispose();
Console.WriteLine("Demo stop: Delegate Chat Server.");
} private static void EventChatServerDemo() {
Console.WriteLine("\n\nDemo start: Event Chat Server.");
EChatClient cc1 = new EChatClient("1");
EChatClient cc2 = new EChatClient("2");
EChatClient cc3 = new EChatClient("3"); EChatServer.SendMsg("Hi to all clients");
EChatServer.SendMsg("Hi to all clients except client 2", cc2); // Explicitly disconnect the clients from the chat server.
// If we didn't do this, the clients' memory could not be
// reclaimed until the server is collected (app shutdown time).
cc1.Dispose();
cc2.Dispose();
cc3.Dispose();
Console.WriteLine("Demo stop: Event Chat Server.");
} public static void Main() {
DelegateChatServerDemo();
EventChatServerDemo();
}
}