有人可以解释System.Timer
对ElapsedEventHandler
的作用吗?我不明白这种语法:
private readonly System.Timers.Timer _timer7 = new System.Timers.Timer();
this._timer7.Elapsed += (ElapsedEventHandler) ((A_1, A_2) =>
{
this._logger.LoggingOfError("T7-Timeout");
});
答案 0 :(得分:0)
您的问题的代码与以下代码相同:
...
19982
19983
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-26-36305ee0e8ef> in <module>()
----> 1 for i,(label, img) in enumerate(dataset):
2 print(i)
4 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)
InvalidArgumentError: ValueError: Tensor's shape (7,) is not compatible with supplied shape [48, 48, 1]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py", line 209, in __call__
ret = func(*args)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 525, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))
File "<ipython-input-25-196a9ac04fc0>", line 5, in img_resize_and_crop_genr
img.set_shape([side_len, side_len,1])
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 981, in set_shape
(self.shape, shape))
ValueError: Tensor's shape (7,) is not compatible with supplied shape [48, 48, 1]
[[{{node PyFunc}}]] [Op:IteratorGetNextSync]
与以下相同:
_timer7.Elapsed += (sender, e) =>
{
_logger.LoggingOfError("T7-Timeout");
};
您可以在此处获得有关匿名方法的说明:
答案 1 :(得分:0)
System.Timers.Elapsed
是ElapsedEventHandler
的类型,定义如下:
public delegate void ElapsedEventHandler(object sender, ElapsedEventArgs e);
为delegate
注册的_timer7.Elapsed
是Lambda Expression(匿名方法)。
A_1
是sender
,而A_2
是e
。
因此,将触发_timer7.Elapsed
时,将调用带有参数A_1
为sender
和A_2
为e
的匿名方法。
这将导致行this._logger.LoggingOfError("T7-Timeout");
被执行