0

I am currently responsible for one of our web tools to copy products between different shares. Everything works fine until now, but now I have a little problem. There is a specific Product type that is very big (about 30 GB). Since this type of jobs doesn't occur very often and the robocopy job works fine, we decided to start the asynchronous task for this specific type.

This is the working action for the normal Packages:

    public JsonResult MovepackagetoMaster(string packagename, CopyStructure structure)
    {
        Robocopy2.WSPackaging objPayRef = new Robocopy2.WSPackaging();
        objPayRef.UseDefaultCredentials = true;
        var CopyStatusInfo = objPayRef.MovePackageToMaster(packagename, structure);
        return Json(CopyStatusInfo.RobocopyError, JsonRequestBehavior.AllowGet);
    }

Now I tried to make a second action which runs asynchronously, but I keep getting errors. My current state looks like that:

    public async System.Threading.Tasks.Task<JsonResult> MovepackagetoMaster2(string packagename, CopyStructure structure)
    {
        Robocopy2.WSPackaging objPayRef = new Robocopy2.WSPackaging();
        objPayRef.UseDefaultCredentials = true;
        var CopyStatusInfo = await objPayRef.MovePackageToMasterAsync(packagename, structure);
        return Json(CopyStatusInfo.RobocopyError, JsonRequestBehavior.AllowGet);
    }

The current error is cannot await void

Can someone here help me how to run this job asynchronously?

The async version of that task wasn't designed by me but currently they look like that:

    public RequestResult MovePackageToMaster(string package, CopyStructure structure) {
        object[] results = this.Invoke("MovePackageToMaster", new object[] {
                    package,
                    structure});
        return ((RequestResult)(results[0]));
    }

    /// <remarks/>
    public void MovePackageToMasterAsync(string package, CopyStructure structure) {
        this.MovePackageToMasterAsync(package, structure, null);
    }

    /// <remarks/>
    public void MovePackageToMasterAsync(string package, CopyStructure structure, object userState) {
        if ((this.MovePackageToMasterOperationCompleted == null)) {
            this.MovePackageToMasterOperationCompleted = new System.Threading.SendOrPostCallback(this.OnMovePackageToMasterOperationCompleted);
        }
        this.InvokeAsync("MovePackageToMaster", new object[] {
                    package,
                    structure}, this.MovePackageToMasterOperationCompleted, userState);
    }
chrigu91
  • 9
  • 2
  • 5
    Is the return of `MovePackageToMasterAsync` a Task<>? – Thibaut Jun 08 '20 at 08:09
  • No as far as i can see it the async version of the task doesnt has a return at all. – chrigu91 Jun 08 '20 at 11:46
  • This is the reason of your problem, you can not transform a sync method (= a method who not return `Task`) in async just by writting`await` key word. Your deepest method (who really do the copy) must be async, otherwise your method will never be asynchronous. – Thibaut Jun 08 '20 at 12:04
  • Does this answer your question? [How can I use async/await to call a webservice?](https://stackoverflow.com/questions/14103288/how-can-i-use-async-await-to-call-a-webservice) In your case it'll be `OnMovePackageToMasterOperationCompleted` instead of `loginCompleted` – ASpirin Jun 08 '20 at 12:04
  • Thank you all for the information i will work myself trough that Link now ASpirin. – chrigu91 Jun 08 '20 at 13:38

0 Answers0