开发者

ASP.NET - VB.NET - Shared methods

开发者 https://www.devze.com 2022-12-19 00:08 出处:网络
I have a method name \"LogClick\" that is called 2 or more times per second. I call it in the tradicional way:

I have a method name "LogClick" that is called 2 or more times per second. I call it in the tradicional way:

Call New MyClass().LogClick()

Everty time I call "LogClick", the "MyClass" is instanciated. So I think: "why not transform this method to shared?"

Publ开发者_如何学运维ic Shared Sub LogClick()
...
End Sub

MyClass.LogClick()

Will I have performance, concurrence ou memory problems transforming this method to shared?


]Hey,

No performance issues per se, but any variables that are static as well will be retained in memory, even in ASP.NET. So you have to account for that. But generally, if there aren't any static variables, performance will be the same as an instance... depending on what's in the instance it may be better with a static method.

HTH.


Shared (static in C#) is inherently non-thread safe, as all your page instances will be accessing the same object.

"Problems" entirely depends on what LogClick() is doing. You'll have to be very careful to analyze the code, assuming that execution will transfer to a different thread after every line is executed, and come back afterwards.

0

精彩评论

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