简体   繁体   English

重载解析失败,因为无法使用这些参数调用可访问的“睡眠”

[英]Overload resolution failed because no accessible `Sleep` can be called with these arguments

I have the following code: 我有以下代码:

Dim MyFile As String
MyFile = ("C:\Book1.xlsx")
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(MyFile)
Threading.Thread.Sleep(infoReader.Length / 1000)

How can I solve the following error: 如何解决以下错误:

在此处输入图片说明

您需要将数字(双精度)转换为timeSpan:

Dim sleepTime As Timespan = TimeSpan.FromSeconds(infoReader.Lenth/1000) 

The result a division operation ( infoReader.Length / 1000 ) is a floating point number ( Double in our case since FileInfo.Length property is of type Long ). 结果除法运算( infoReader.Length / 1000 )是一个浮点数(在本例中为Double ,因为FileInfo.Length属性的类型为Long )。

On the other hand, the Threading.Thread.Sleep() overload you're most likely wanting to use expects an Int parameter. 另一方面,您最有可能要使用的Threading.Thread.Sleep()重载期望使用Int参数。

Cast the division result to Int explicitly (is the files are not too big): 将除法结果显式转换为Int (文件不是太大):

Threading.Thread.Sleep(CInt(infoReader.Length / 1000))

Or use the second overload accepting TimeSpan , using the FromMilliseconds method which accepts Double : 或者使用第二个重载接受TimeSpan ,使用FromMilliseconds方法接受Double

Threading.Thread.Sleep(TimeSpan.FromMilliseconds(infoReader.Length / 1000))

Divide it using the integer division. 用整数除法将其除。 The sleep function doesn't take a double as parameter. sleep函数不使用double作为参数。

Threading.Thread.Sleep(infoReader.Length \ 1000)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重载解决失败,因为无法使用这些参数调用可访问的“加入” - Overload resolution failed because no accessible 'Join' can be called with these arguments 实体框架:重载解析失败,因为无法使用这些参数调用可访问的ORDERBY - Entity Framework: Overload resolution failed because no accessible ORDERBY can be called with these arguments 重载解析失败,因为对于这些参数,没有可访问的“新”是最具体的 - Overload resolution failed because no accessible 'new' is most specific for these arguments 重载解析失败,因为没有可访问的“新”是这些参数最具体的: - Overload resolution failed because no accessible 'New' is most specific for these arguments: 重载解析失败,因为没有可访问的'writealltext'接受此数量的参数 - overload resolution failed because no accessible 'writealltext' accepts this number of arguments 重载解析失败,因为没有可访问的“ DataBind”最特定于这些参数 - overload resolution failed because no accessible 'DataBind' is most specific for these arguments 重载解析失败,因为没有可访问的“参数”接受此数量的 arguments - Overload resolution failed because no accessible 'Parameters' accepts this number of arguments 重载解析失败,因为没有可访问的“新”接受此数目的参数 - overload resolution failed because no accessible 'new' accepts this number of arguments 重载解析失败,因为没有可访问的“ ExecuteScalar”接受此数量的参数 - Overload resolution failed because no accessible 'ExecuteScalar' accepts this number of arguments Visual Basic重载分辨率失败,因为无法调用可访问的“新建”,错误 - Visual Basic Overload resolution failed because no accessible 'New' can be called, error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM