FoxPro and .NET Interop
Indicate timewout to wwDotNetBridge
Gravatar is a globally recognized avatar based on your email address. Indicate timewout to wwDotNetBridge
  Alejandro A Sosa
  All
  May 29, 2020 @ 12:23pm

Is it possible to tell wwDotNetBridge how long it should wait before throwing an error?

TIA,

Alex

Gravatar is a globally recognized avatar based on your email address. re: Indicate timewout to wwDotNetBridge
  Rick Strahl
  Alejandro A Sosa
  May 30, 2020 @ 02:44pm

No.

You're making a COM call and that will do whatever it needs to.

If you're worried about timeouts you should make async calls that you can cancel.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Indicate timewout to wwDotNetBridge
  Alejandro A Sosa
  Rick Strahl
  May 30, 2020 @ 06:50pm

Ok, thanks a lot.

Alex

Gravatar is a globally recognized avatar based on your email address. re: Indicate timewout to wwDotNetBridge
  Alejandro A Sosa
  Rick Strahl
  May 31, 2020 @ 05:35pm

Hi Rick,

Thanks for suggesting async calls that you can cancel.

After reading about Task classes and the fact that task cancellation involves cooperation between the user delegate and the code that requested the cancellation, I took the following "short cut" which is working so far:

In your SignalRClient code I replaced Server.Start().Wait(); with this.

  var task = Task.Run(() =>
  {
      Server.Start().Wait(2100);
  });
  bool isCompletedSuccessfully = task.Wait(TimeSpan.FromMilliseconds(2000));
  Fox = foxHandler;
  return isCompletedSuccessfully;

I'd like to end the program properly, with something like System.Environment.Exit(1);, but the method must return isCompletedSuccessfully because the calling program needs to know the status.

Thanks again,

Alex

Gravatar is a globally recognized avatar based on your email address. re: Indicate timewout to wwDotNetBridge
  Rick Strahl
  Alejandro A Sosa
  Jun 1, 2020 @ 12:39pm

Oh no, no, no! Don't do this please...

The code is absolutely pointless as it will just sit and wait for the async operation to complete. Anytime you .Wait() or access .Result you are synchronously waiting for the async operation to complete. IOW, in the code you posted the Task.Run() isn't asynchronous at all. In fact it's worse than that because it actually uses more resources on a separate thread, switches thread context adds a compile time generated state machine etc... Lots of extra overhead for no gain and no async operation.

wwDotnetBridge already includes methods you can can to asynchronously call any .NET instance method using InvokeMethodAsync() and there was recently another method added that allows calling .NET Async methods via InvokeTaskMethodAsync().

This provides some background on how Async/Await works in .NET and how it affects FoxPro calling that code:

Calling Async/Await .NET methods with wwDotnetBridge

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Indicate timewout to wwDotNetBridge
  Alejandro A Sosa
  Rick Strahl
  Jun 1, 2020 @ 08:13pm

Thank you very much for the heads up Rick.

Alex

© 1996-2024