简体   繁体   English

VBA 是否支持从 C# 类导入的 Task.Wait()?

[英]Does VBA support Task.Wait() from a C# class import?

I wrote a C# class which connects to Dropbox and lets you upload, download, delete and generate link files.我编写了一个 C# 类,它连接到 Dropbox 并允许您上传、下载、删除和生成链接文件。

It's working with a Windows Forms but I have to access it from VBA (Microsoft Access).它正在使用 Windows 窗体,但我必须从 VBA (Microsoft Access) 访问它。 The problem comes when it goes to task.Wait().当它转到 task.Wait() 时,问题就来了。 I've ""debugged" this throwing Exceptions and after that, doesn't go through.我已经“调试”了这个抛出的异常,然后就没有通过。

public DropBox()
{
    //Empty constructor because VBA doesn't support constructors with args
}

public void Connect(string tokenUser)
{
    try
    {
        dropbox = new DropboxClient(tokenUser);
        var taskInicio = Task.Run(async () => await dropbox.Users.GetCurrentAccountAsync());
        //throw new Exception("Arriving?");   //ARRIVES
        taskInicio.Wait();
        throw new Exception("Arriving?");    //Throws "one or more errors"
    }
    catch (AggregateException ex)
    when (ex.InnerException is BadInputException
          || ex.InnerException is AuthException)
    {
        throw new Exception("Incorrect Token or without access", ex.InnerException);
    }
}

On VBA在 VBA 上

Option Compare Database

Private Sub btActivar_Click()
    Call test
End Sub

Public Function test()

    Dim objDrop As CloudFiles.DropBox
    Set objDrop = New CloudFiles.DropBox

    MsgBox (objDrop.HolaMundo)
    objDrop.Connect("TokenLongChicken")
    'objDrop.DeleteFile("https://www.dropbox.com/s...?dl=0")


End Function

The "One or more errors produced" sounds like it comes from the "mscorlib" or so... “产生一个或多个错误”听起来像是来自“mscorlib”左右......

Any ideas?有任何想法吗? This is getting quite messy :/这变得非常混乱:/

Thanks.谢谢。

VBA does have Application.Wait , I think you can give it a try. VBA 确实有Application.Wait ,我想你可以试一试。 I have a code to wait for an IE connection which you can use as example:我有一个等待 IE 连接的代码,您可以将其用作示例:

Do While IE.Busy ' Need to wait until the page has loaded
  Application.Wait (Now + TimeValue("00:00:01")) ' Wait one second
Loop

Tell me if it helps you.告诉我它是否对你有帮助。

I was having headaches thinking that it could be something related with the Tasks, asyncs, awaits... and it was something related with the Newtonsoft json library.我很头疼,认为它可能与任务、异步、等待有关……而它与 Newtonsoft json 库有关。

I updated the library through the NuGet to the 9.0 version and everything worked fine on Windows Forms, but looks like something is wrong when I use it through the .TLB because when I escaped the exception I got at some point in my deletion method, it said the Newtonsoft Json 7.0.0.0 library was missing (it was at the same directory anyway).我通过 NuGet 将库更新到 9.0 版本,并且在 Windows Forms 上一切正常,但是当我通过 .TLB 使用它时看起来有些问题,因为当我逃避异常时,我在删除方法中的某个时候,它说缺少 Newtonsoft Json 7.0.0.0 库(无论如何它都在同一目录中)。

I finally removed that Newtonsoft Json version I was using and the Dropbox API, downloaded box again but I declined applying any updates.我终于删除了我正在使用的 Newtonsoft Json 版本和 Dropbox API,再次下载了框,但我拒绝应用任何更新。 I couldn't even try to apply a downgrade or so.我什至无法尝试申请降级左右。

Good ending, but I don't really get why did it search for the 7.0.0.0 when I was using the 9.x on my Windows Form project, which works and exported the .DLL and the .TLB.好的结局,但我真的不明白为什么当我在我的 Windows 窗体项目中使用 9.x 时它搜索 7.0.0.0,它可以工作并导出 .DLL 和 .TLB。

Thanks to everybody.感谢大家。

EDIT: And yes, I guess this answers the question: VBA supports Task.Wait (at least coming from a C# .dll import)编辑:是的,我想这回答了这个问题:VBA 支持 Task.Wait(至少来自 C# .dll 导入)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM