开发者

Is there any performance overhead in using RaiseEvent in .NET?

开发者 https://www.devze.com 2022-12-28 18:05 出处:网络
Is there any performance overhead in using RaiseEvent in .NET? I have a code which is similar to following.

Is there any performance overhead in using RaiseEvent in .NET?

I have a code which is similar to following.

Dim _startTick As Integer = Environment.TickCount
'Do some Task'
Dim duration As Integer = Environment.TickCount - _s开发者_如何学编程tartTick
Logger.Debug("Time taken: {0}", duration)
RaiseEvent Datareceived()

The above code returns:

Time taken: 1200

Time taken: 1400

But if I remove RaiseEvent it returns:

Time taken: 110

Time taken: 121

I am surprised that the RaiseEvent is called after the logging of time taken. How does it affect the total time taken?

I am working on .NET Compact Framework.

In the Eventhandler I had given a MsgBox. When I removed the message box, it is now showing time taken as 110, 121, etc., that is, less that 500 milliseconds. If I put the Msgbox back in eventhandler it shows 1200, 1400, etc., that is, more than a second.

I am more surprised now (the event is raised after the logging part).


Try using the same in a console application. A console application uses fewer resources.

Here you can identify the exact issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号