VB.NET中,若频繁并发调用同一共享函数,会有何影响?

2026-04-29 07:192阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计520个文字,预计阅读时间需要3分钟。

VB.NET中,若频繁并发调用同一共享函数,会有何影响?

考虑以下简化的伪原创开头内容:

实现一个公共共享功能:计算半径的面积。使用公式:面积=π * 半径²。

vbPublic Shared Function CalculateAreaFromRadius(ByVal radius As Double) As Double ' 将半径平方... Dim radiusSquared As Double radiusSquared=radius * radius ' 乘以π... Dim result As Double result=radiusSquared * Math.PI ' 返回结果 Return resultEnd Function

考虑一下我有一个共享功能: –

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?

VB.NET中,若频繁并发调用同一共享函数,会有何影响?

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

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?

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

本文共计520个文字,预计阅读时间需要3分钟。

VB.NET中,若频繁并发调用同一共享函数,会有何影响?

考虑以下简化的伪原创开头内容:

实现一个公共共享功能:计算半径的面积。使用公式:面积=π * 半径²。

vbPublic Shared Function CalculateAreaFromRadius(ByVal radius As Double) As Double ' 将半径平方... Dim radiusSquared As Double radiusSquared=radius * radius ' 乘以π... Dim result As Double result=radiusSquared * Math.PI ' 返回结果 Return resultEnd Function

考虑一下我有一个共享功能: –

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?

VB.NET中,若频繁并发调用同一共享函数,会有何影响?

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

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?

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