dingmaotu / mql-zmq

ZMQ binding for the MQL language (both 32bit MT4 and 64bit MT5)
Apache License 2.0
553 stars 301 forks source link

EA中的 反初始化函数疑问 #72

Closed helloktity closed 5 months ago

helloktity commented 5 months ago

//+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Print("[REP] Unbinding MT4 Server from Socket on Port " + (string)REP_PORT + ".."); repSocket.unbind(StringFormat("%s://%s:%d", ZEROMQ_PROTOCOL, HOSTNAME, REP_PORT)); Print("[SUB] Unbinding MT4 Server from Socket on Port " + (string)SUB_PORT + ".."); subSocket.disconnect(StringFormat("%s://%s:%d", ZEROMQ_PROTOCOL, "192.168.3.88", SUB_PORT));

//不需要下面的关闭和销毁上下文,如果加上的话 不能正常反初始化 只需要上方的代码即可 //这行代码调用 ZeroMQ 上下文对象的 shutdown 方法,用于关闭 ZeroMQ 上下文。上下文对象是 ZeroMQ 库中的一个重要对象,它负责管理套接字、线程和其他资源。 //context.shutdown(); //这行代码调用 ZeroMQ 上下文对象的 destroy 方法,用于销毁 ZeroMQ 上下文。参数 0 表示立即销毁上下文,释放所有资源。 // context.destroy(0); EventKillTimer();

} 一个不太理解的事情 就是 如果使用 context.shutdown(); context.destroy(0); 则 如果切换图标周期,就不能再使用了,除非重启客户端,如果 不加这两句 则切换图标周期没有问题。 关闭和 销毁context 不是在 别的语言中 常规的操作吗?

helloktity commented 5 months ago

经过测试 应该是 根据reason 的值 有所区分才行,只有 reason == REASON_REMOVE 或者 reason == REASON_CHARTCLOSE 这类情况 才可以 context.shutdown(); context.destroy(0);

Abbotton commented 4 months ago

Hi, 付费求助, 方便的话可以加一下我微信吗?我的微信号: abbotton 非常感谢.