vb.net - VB .NET 共享函数如果同时调用多次

标签 vb.net function accessibility shared

考虑我有一个共享功能:-

Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As Double

    ' square the radius...
    Dim radiusSquared As Double
    radiusSquared = radius * radius

    ' multiply it by pi...
    Dim result As Double
    result = radiusSquared * Math.PI

    'Wait a bit, for the sake of testing and 
    'simulate another call will be made b4 earlier one ended or such
     for i as Integer = 0 to integer.Max
     Next

    ' return the result...
    Return result

End Function

我的问题:
  • 如果我在同一个 vb .net 应用程序中有两个或多个线程,并且每个线程同时使用不同的 RADIUS 调用共享函数,它们会各自获得自己的区域吗?
  • 我想知道对函数的每次调用是使用相同的局部变量还是每次调用都会创建局部变量的新实例?
  • 如果我有多个 (2+) 单线程应用程序并且它们都使用不同的 RADIUS 值同时调用该函数,上述问题的答案是否相同?

  • 我会很感激你的回应。谢谢你。

    最佳答案

    1) If I have two or more threads in the same vb .net app and each of them calls the shared function at the same time with different RADIUS, will they each get their own AREA?



    是的,因为半径值是按值传递的,并且该方法只使用本地声明变量。

    2) I want to know for each call to the function if it is using same local variables or each call creates new instances of local variables?



    每次调用都会创建其局部变量的新实例。

    3) Will the answers to above questions be same If I have multiple (2+) single threaded apps and they all call the function at the same time with different RADIUS value?



    是的。同样,因为没有信息的共享存储,并且因为所有输入都是按值传递的,所以它是线程安全的。

    关于vb.net - VB .NET 共享函数如果同时调用多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2519356/

    相关文章:

    vb.net - 如何让按钮背景透明?

    javascript - 确认功能不起作用

    c - C语言中函数有存储类吗?

    r - 在 R 中编写函数

    ios - Swift IOS 中的辅助功能画外音单次滑动手势

    vb.net - 如何在 Visual Studio 2015 中更改 VB.NET 语言版本

    c# - 如何在 .NET 中映射需要用户名和密码的网络驱动器?

    c# - 与 DropDownList 中的自动回发相关的问题

    javascript - aria-owns、aria-invalid、aria-expanded的解释和示例

    css - 如何仅从屏幕阅读器而不是普通用户的页面隐藏页面中的任何元素?