我目前正在使用 WCF 应用程序。我必须在 DataGridView 中显示从回调接收到的数据。这些是我的代码:
从 FrmMain 形式:
private void button1_Click(object sender, EventArgs e)
{
InstanceContext callbackInstance = new InstanceContext(new StockExchangeUpdates());
SubscribingClient.RegisterSubscriberServiceClient proxy = new SubscribingClient.RegisterSubscriberServiceClient(callbackInstance);
proxy.RegisterSubscriber(Guid.NewGuid());
}
类 StockExchangeUpdates
[CallbackBehavior(UseSynchronizationContext = false)]
public class StockExchangeUpdates : IRegisterSubscriberServiceCallback
{
int ctr = 0;
FrmMain main = new FrmMain();
public void passGeneratedNumber(int num)
{
try
{
ctr = ctr + 1;
main.dgRandom.Rows.Add(DateTime.Now.ToString("h:mm:ss"), num, ctr);
// this is not working..
// Error: "dgRandoms" is inaccessible due to its protection level
}
catch (Exception)
{
throw;
}
}
}
我习惯了尝试不同的方法,但它仍然无法正常工作。请帮忙!非常感谢!