Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LongSack
Jan 17, 2003

In WPF, if I set the WindowState to Maximized, and the ResizeMode is set to either CanMinimize or NoResize, then the window covers the task bar. If ResizeMode is set to either of the “can resize” modes, the window does not cover the task bar.

My googling has only turned up fixes for this when WindowStyle is set to None, but mine is set to ThreeDBorderWindow. I even tried some of the fixes I came across in google, to no effect. This happens in both Windows 8.1 and 10.

Any ideas besides using CanResize which is my current fix?

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice
I just updated to VS 15.5, which according to the release notes should let me create new .NET Standard libraries in F#. But I don’t have any new templates. How do I figure out what’s going on? I just re-installed the .NET Core SDK, to make sure I have it.

Scikar
Nov 20, 2005

5? Seriously?

raminasi posted:

I just updated to VS 15.5, which according to the release notes should let me create new .NET Standard libraries in F#. But I don’t have any new templates. How do I figure out what’s going on? I just re-installed the .NET Core SDK, to make sure I have it.

Did you install VS with F# support? I can't remember if it's selected by default but there are definitely a bajillion options now and F# is one of them.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Does Visual Studio automatically show the templates from the new SDK? If it does not, the command you want is "dotnet new classlib -lang f#".

raminasi
Jan 25, 2005

a last drink with no ice

Scikar posted:

Did you install VS with F# support? I can't remember if it's selected by default but there are definitely a bajillion options now and F# is one of them.

Well, I just did the upgrade. I assume that since F# was already installed it would be upgraded.

NihilCredo posted:

Does Visual Studio automatically show the templates from the new SDK? If it does not, the command you want is "dotnet new classlib -lang f#".

The release notes sure imply that it should!

raminasi
Jan 25, 2005

a last drink with no ice
I converted an F# project to the new .fsproj format and now C# code depending on it can't call record properties without causing a CS1546 or a CS0570 did nobody test any of this at all

Mr Shiny Pants
Nov 12, 2012

raminasi posted:

I converted an F# project to the new .fsproj format and now C# code depending on it can't call record properties without causing a CS1546 or a CS0570 did nobody test any of this at all

Heh, I gave up om the bleeding edge MS stuff for awhile now. Life got a lot simpler.

mystes
May 31, 2006

raminasi posted:

F#... did nobody test any of this at all
Unfortunately it seems like the answer is usually no.

mystes fucked around with this message at 23:08 on Dec 20, 2017

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Anyone have any idea how to do something like add a custom .NET Framework build to the VS "target framework" options? (Or where that list comes from in general?)

raminasi
Jan 25, 2005

a last drink with no ice

OneEightHundred posted:

Anyone have any idea how to do something like add a custom .NET Framework build to the VS "target framework" options? (Or where that list comes from in general?)

Like, you forked the framework itself? I have no idea how to do that but I’m really curious about whatever project you’re doing that calls for it.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

raminasi posted:

I’m really curious about whatever project you’re doing that calls for it.
I'm trying to make a miniature .NET runtime because Lua is slow and Mono is huge, but the mscorlib I'm using is a fork of the .NET Micro Framework.

OneEightHundred fucked around with this message at 07:05 on Dec 21, 2017

Xik
Mar 10, 2011

Dinosaur Gum
I'm working on an web api that makes numerous other network/service calls. All of them except one are called using libraries that we have either built internally (async all the way down), or are generic enough to use out of the box framework async clients to call. The problem is that last one, it's a proprietary service, and their proprietary .NET library does not expose async calls.

What are my options (if any)? This one call is like 50% of my response time but under the hood is just another network call.

I guess this is sort of embarrassing, but as part of this team I've built dozens of web apis, but I've never had to deal with I/O bound work that doesn't expose awaitable signatures.

EssOEss
Oct 23, 2006
128-bit approved
I would just fake it with a worker thread - your main code thinks it is some async operation going on but really, all that happens is that a new thread is started and the work done on that thread in parallel.

This would be Task.Run(() => SyncOperation(), TaskOptions.LongRunning), which returns a Task you can await. You want to specify LongRunning (which starts a new thread every time) so you do not eat up thread pool threads with long blocking synchronous network operations (my rule of thumb: 10+ milliseconds per call is long running).

Depending on your performance needs, the model might be futher optimized but the above should be a good starting point.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Any idea why an explicit operator to convert a string to my object type might screw up? I also have a TypeConverter on it. I've pastebinned it since it's over 100 lines.

SirViver
Oct 22, 2008

Rocko Bonaparte posted:

Any idea why an explicit operator to convert a string to my object type might screw up? I also have a TypeConverter on it. I've pastebinned it since it's over 100 lines.
Can you give a hint where you're expecting your cast operator to be used? Because as it stands, there is not a single cast from string to SceneObjectId in that code.

The closest I could find was:
C# code:
public void LoadFromSerializer(object serializedHandle, TEntity parent, Dictionary<SceneObjectId, TEntity> objectMap)
...
    var converted = (TRecord)serializedHandle; // TRecord => SceneObjectId
But in this case serializedHandle is an object, not a string. Note that cast operators are evaluated at compile-time and do not perform any runtime type checks. The only way your cast operator would be used is if you manually check whether serializedHandle is a string and then use var converted = (TRecord)(string)serializedHandle;

To demonstrate, check this code snippet. On the left you see the C# code as you'd write it and on the right the "raw" code that the compiler actually generates. Note how only the cast on the actual string variable performs the call to the operator, but the cast on the same string being referenced via an object variable does not.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

SirViver posted:

But in this case serializedHandle is an object, not a string.

That must be it. The case where I want it to work is when that object turns out to be a string. I may add a cast for that too and throw an InvalidCastException if it does not like me. I have not been able to contort that generic code any further to support it there; TRecord could be an object or a primitive type, so the compiler gets pissed at me even though I went through all the motions to determine it was a string.

I had made the particular case just make it's TRecord be a string, but that SceneObjectId type is very common. It is how I reconnect some saved entities when doing all that loading.

Edit: ...and I can't create an explicit cast operator from an object due to the whole "user-defined conversions to or from a base class are not allowed."

Rocko Bonaparte fucked around with this message at 20:02 on Dec 21, 2017

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



OneEightHundred posted:

Anyone have any idea how to do something like add a custom .NET Framework build to the VS "target framework" options? (Or where that list comes from in general?)

I bet the easiest way, if it's possible, is to pull apart an installer for the 2.x framework SDK and replace their DLLs with yours.

The process monitor logs make it look like it just crawls C:\Program Files (x86)\Reference Assemblies and C:\Program Files (x86)\Microsoft SDKs but I'm sure it's more complicated than that and I don't really have time to analyze it thoroughly.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

OneEightHundred posted:

I'm trying to make a miniature .NET runtime because Lua is slow and Mono is huge, but the mscorlib I'm using is a fork of the .NET Micro Framework.

Is https://nanoframework.net/about/ anything close to what you want?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

NihilCredo posted:

Is https://nanoframework.net/about/ anything close to what you want?
No, the .NET Micro Framework is a slow-but-memory-efficient interpreter and only supports .NET 1 level features. I want to make something that's fast and supports generics at least.

I want to support variance too, but it's a nightmare of poor planning, poor specification, and undocumented behavior that violates the spec.

ljw1004
Jan 18, 2005

rum

OneEightHundred posted:

I want to support variance too, but it's a nightmare of poor planning, poor specification, and undocumented behavior that violates the spec.

What variance things? I could maybe help.

My first proper feature on the VB/C# compiler team was to implement co- and contra-variance in the language. I was fresh out of academia so I accompanied my implementation with a proof of correctness. Or at least, tried to, but the proof didn't work because of a "diamond bug" in the pre-existing CLR specification. I presented the flaw, and possible remedies, and that was enough to get me invited onto the language design team. Fun memories :)

Mr Shiny Pants
Nov 12, 2012
Diamond bug? You'll have to explain that one. :)

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

ljw1004 posted:

What variance things? I could maybe help.

My first proper feature on the VB/C# compiler team was to implement co- and contra-variance in the language. I was fresh out of academia so I accompanied my implementation with a proof of correctness. Or at least, tried to, but the proof didn't work because of a "diamond bug" in the pre-existing CLR specification. I presented the flaw, and possible remedies, and that was enough to get me invited onto the language design team. Fun memories :)
I feel like I've had this rant before...

I bugged a bunch of cases in Mono this morning, including the worst case that I'm aware of. It's not a compilation problem, it's an execution problem.

For one thing, the .NET interface dispatch specification follows a practice that I've seen in other specifications and that I hate: Describing an algorithm using a completely-impractical reordering of it for the sake of... uh, I guess clustering the operations to avoid talking about control flow? I don't know. Adding and removing stuff from a list and selecting a candidate out of it is just a slow way of implementing a tiered priority system, except now I have to puzzle out what the real algorithm is and that makes it harder to implement it correctly and validate compliance.

My interpretation of it was that because all of the candidate methods would be prioritized the same way, calls through a variant interface would at least be 1:1 with one of the interfaces on the class. I'm guessing that's how 99% of people would think it works, and it'd allow for some nice under-the-hood optimizations like handling the whole cast as just aliasing one of the implementation tables.

Unfortunately, it doesn't work that way, and it's possible for a variant interface to have a different set of implementations than any interface on the actual class because of a quirk where it makes a distinction between new and reused method implementations, and reused implementations are invisible to the call resolution search. Nothing in the spec even hints at this, so it's either undocumented behavior or a bug, and it forced a rewrite of the interface call code, which now has to do lookups at runtime.

This is on top of quirks that ARE documented in the spec, like situations where a match by variance take priority over exact matches, and the whole existence of "type declaration order" instead of traversing the class hierarchy, that make the whole thing seem poorly thought out to me.

But here's the annoying case:

code:
interface IIfc { }

class A { }
class B : A { }
class C : B, IIfc { }

interface IVar<in T> { void P(T v); }
class S1
{
    public virtual void P(B v) { Console.WriteLine("Called S1.B"); }
    public virtual void P(A v) { Console.WriteLine("Called S1.A"); }
}
class S2 : S1, IVar<B>
{
}

class S3: S1, IVar<B>, IVar<IIfc>
{
    void IVar<IIfc>.P(IIfc v) { Console.WriteLine("Called S3.IIfc"); }
}

class S4: S2, IVar<B>, IVar<IIfc>
{
    void IVar<IIfc>.P(IIfc v) { Console.WriteLine("Called S4.IIfc"); }
}

class S5: S2, IVar<B>, IVar<IIfc>
{
    void IVar<B>.P(B v) { Console.WriteLine("Called S5.B"); }
    void IVar<IIfc>.P(IIfc v) { Console.WriteLine("Called S5.IIfc"); }
}

public static void Main()
{
    ((IVar<C>)new S3()).P(null);
    ((IVar<C>)new S4()).P(null);
    ((IVar<C>)new S5()).P(null);
}
Output:
code:
Called S1.B
Called S4.IIfc (what?)
Called S5.B

OneEightHundred fucked around with this message at 17:25 on Dec 22, 2017

Xik
Mar 10, 2011

Dinosaur Gum

EssOEss posted:

I would just fake it with a worker thread - your main code thinks it is some async operation going on but really, all that happens is that a new thread is started and the work done on that thread in parallel.

This would be Task.Run(() => SyncOperation(), TaskOptions.LongRunning), which returns a Task you can await. You want to specify LongRunning (which starts a new thread every time) so you do not eat up thread pool threads with long blocking synchronous network operations (my rule of thumb: 10+ milliseconds per call is long running).

Depending on your performance needs, the model might be futher optimized but the above should be a good starting point.

Thanks for this. I only had like half an hour today to play with things, but I wasn't seeing the results I expected (I used the TaskFactory). I'm finished for the year now, but I'll probably spend some time during my break to learn more about Task creation.

epswing
Nov 4, 2003

Soiled Meat

OneEightHundred posted:

But here's the annoying case:

code:
...
class S5: S2, IVar<B>, IVar<IIfc>
{
    void IVar<B>.P(B v) { Console.WriteLine("Called S5.B"); }
    void IVar<IIfc>.P(IIfc v) { Console.WriteLine("Called S5.IIfc"); }
}
...

Yikes. I've been down a similar rabbit hole in WPF/MVVM with many layers of inheritance, interfaces, generics, the works. It was fun to implement and understand co/contra-variance'ness, fun to write and design, but when something broke, or needed to be moved, it was a nightmare (especially due to errors that didn't quite tell you where to look). Isn't that what they say about perl (or is it regex)? Fun to write, hard to read?

After a couple projects like that, I've been on a simplicity crusade for the last couple of years. I've found that a little bit of code duplication is sometimes worth it, to avoid ridiculous complexity that only one guy in your company understands on Tuesdays and Thursdays. Maybe this is an unpopular opinion in a thread full of smart people, but as I age my focus has slowly shifted away from "oh that's so cool!!".

And it IS cool stuff!

epswing fucked around with this message at 16:34 on Dec 22, 2017

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

epalm posted:

After a couple projects like that, I've been on a simplicity crusade for the last couple of years. I've found that a little bit of code duplication is sometimes worth it, to avoid ridiculous complexity that only one guy in your company understands on Tuesdays and Thursdays. Maybe this is an unpopular opinion in a thread full of smart people, but as I age my focus has slowly shifted away from "oh that's so cool!!".
To be clear, S4 is the crazy case: The IVar<B> in S4 isn't used because the method was already implemented by the IVar<B> in S2. S3 and S5 both work because they're implementing the method for the first time. I think that rule only applies to variant matches though (i.e. calling S4 using IVar<B> will call S1.IVar<B>).

I'm waffling on just dropping support for variance and capping at .NET 2 though, which would probably be plenty for the niche that I'm trying to fill.

Mr Shiny Pants
Nov 12, 2012
Is it possible in F# to decorate an existing object with an Interface?

I've been reading about Object Expressions but it is not clicking with me.

So let's say I have a Type of Foo and an Interface of IBar can I make an instance of Foo and let this specific instance implement IBar?

Or am I being too smart for my own good? I would like to have a couple of MailboxProcessors that can have different capabilities, which you would put on the specific instance.

Mr Shiny Pants fucked around with this message at 12:29 on Dec 24, 2017

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Mr Shiny Pants posted:

Is it possible in F# to decorate an existing object with an Interface?

I've been reading about Object Expressions but it is not clicking with me.

So let's say I have a Type of Foo and an Interface of IBar can I make an instance of Foo and let this specific instance implement IBar?

Or am I being too smart for my own good? I would like to have a couple of MailboxProcessors that can have different capabilities, which you would put on the specific instance.

Implementing an interface is a property of a type, not an instance.

You could use object expressions to create ad-hoc implementations:

code:
let myBar = { new IBar with member this.Bar = myFoo.Foo }
but myBar would not be a Foo, it would be an anonymous class implementing IBar.

You could write a function to convert any Foo to an IBar on the spot, which is probably best done as an augmentation (equivalent of a C#/VB.NET extension method):

code:
type Foo with member this.AsIBar =  { new IBar with member that.Bar = this1.Foo }
but it would be equally available to every instance of Foo.

What are, exactly, the different capabilities you want those MailboxProcessors<'t> to have? I'm betting that the correct answer will be to change the generic argument <'t>, not the processor itself.

Mr Shiny Pants
Nov 12, 2012

Well I got it to work:

code:
type Foo() =
    member this.Post(text) = printf "%s" text

type IBar =
    abstract member Send: string -> unit

let foo1 = 
    {
        new Foo() with
            override this.ToString() = base.ToString()
        interface IBar with
            member this.Send(text) = (this :?> Foo).Post(text)

    }

(box foo1 :?> IBar).Send("text")
This seems to work, I don't know how I feel about it yet. :)
Well the idea was that I have some outputs or inputs, which I don't know about yet ( a plugin or something ) , and the system would just gather every object that would have the implementation on it. I have a default mailboxprocessor type which I want to use as a base for all the others but it might not have an output or an input etc.
Now I don't need to subclass my generic processors into specific versions and all the variations of them. Let's say I have 10 capabilities in different variations ( an input might not have an output or something ) then I would need subclass the generic processor in all the variations right?

I was also thinking of just adding a DU of capabilities and querying those, but then I would have no way to know if they are implemented or not.
If you have a different idea, I am happy to hear it.

Edit: and most importantly: Happy holidays! :)

Mr Shiny Pants fucked around with this message at 13:51 on Dec 24, 2017

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

It sounds like you just want a two-way MBP?

If the different inputs / outputs should be processed in the same queue, then use a single MBP instance and organize the inputs / outputs in a DU, as in the example (the messages that expect an output will include an AsyncReplyChannel<'output>). If they should be separate queues, then you can just have different MBPs for each input-output type.

raminasi
Jan 25, 2005

a last drink with no ice

Why did you (box foo1 :?> IBar).Send("text") instead of just (foo1 :> IBar).Send(“text”)?

Mr Shiny Pants
Nov 12, 2012

raminasi posted:

Why did you (box foo1 :?> IBar).Send("text") instead of just (foo1 :> IBar).Send(“text”)?

This does not work it seems, with the box keyword it does.

It gives:
code:
(foo1 :> IBar).Send("bla");;

  (foo1 :> IBar).Send("bla");;
  -^^^^^^^^^^^^

C:\Users\username\AppData\Local\Temp\stdin(8,2): error FS0193: Type constraint mismatch. The type 
    Foo    
is not compatible with type
    IBar    
The type 'Foo' is not compatible with the type 'IBar'

NihilCredo posted:

It sounds like you just want a two-way MBP?

If the different inputs / outputs should be processed in the same queue, then use a single MBP instance and organize the inputs / outputs in a DU, as in the example (the messages that expect an output will include an AsyncReplyChannel<'output>). If they should be separate queues, then you can just have different MBPs for each input-output type.

Not quite, I think. I need to think about this some more. Thanks though.

Mr Shiny Pants
Nov 12, 2012
Another F# question, I have a Kinect running and the speechrecognition engine. The recognition engine runs on it's own thread and has to block for it to keep listening. The sensor and engine need to be disposed when stopping the application.

This is what I came up with:
code:
let listen (recognizer: RecognizerInfo,sensor:KinectSensor,reset:ManualResetEvent) = 
    async{
        printfn "Waiting"
        sensor.Start()
        let engine = new SpeechRecognitionEngine(recognizer.Id)
        buildGrammar (engine, recognizer)
        engine.SpeechRecognized.Add(fun x -> recognized x )
        engine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm,16000,16,1,32000,2,null))          
        engine.RecognizeAsync(RecognizeMode.Multiple)
        reset.WaitOne() |> ignore
        engine.RecognizeAsyncCancel()
        printfn("Stopped recognizer")
        engine.Dispose()
        sensor.Stop()
        sensor.Dispose()
        
    }
        

let EngineControl(engineInfo,sensor,token:CancellationToken) =
    async {
        complete <- new ManualResetEvent(false)
        Async.Start(listen(engineInfo,sensor,complete))
        while not <| token.IsCancellationRequested && sensor.Status = KinectStatus.Connected do
            ()
        complete.Set() |> ignore
    }

Async.Start(EngineControl(info,sensor, cts.Token))
Edit: when writing this I come across: let! token = Async.CancellationToken <- That does not work as I hoped it would. How do I get the passed in Token so I can test on it?
Still, can this be written better?

Mr Shiny Pants fucked around with this message at 12:29 on Dec 27, 2017

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I've never tried this in F#, but it turns out that F# also has a 'use' and 'using' keyword: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/resource-management-the-use-keyword

That should dispose them after your mutex. I'm not sure of F# 'async' actually creates a new thread, I believe it probably just adds a task to the thread pool scheduler. Anyways, since you aren't looping through the task, you can probably just use the 'use' or 'using' context to dispose of your resources.

I think I'd get rid of the 'listen' function and put it into a single task. RecognizeAsync() having blocking and non-blocking calls is weird to me, but the combo of RecognizeAsync(RecognizeMode.Multiple) and CancelRecognizeAsync() seem to do most of the work already. I'd make one task for the building of the engine and the RecognizeAsync(RecognizeMode.Multiple) call. When you exit your program, just call CancelRecognizeAsync() from your main thread and the 'use' and 'using' context keywords should dispose of those resources automatically.

I'm a bit tired so sorry if this isn't your question or if it doesn't make any sense.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

I haven't used that API, but I suspect that it's redundant to both put the whole operation inside an async {} block and use the speech engine's async methods.

Assuming you want to use the synchronous methods with F#'s async system (for example, because buildGrammar is very heavyweight), I'd do something like this:

code:
let startEngine (recognizer: RecognizerInfo) (sensor:KinectSensor) = 
  
  let source = CancellationTokenSource()

  let rec listen engine = 
    async {            
        let recognitionResult = engine.Recognize(RecognizeMode.Multiple)
        do! recognized x
        return! listen engine  
    }   

  let rec checkConnection() = 
    async { 
      match sensor.Status with
      | KinectStatus.Connected -> do! Async.Sleep 100; return! checkConnection()
      | _ -> source.Cancel(); return ()
    }
  
  Async.Start <| async {
      printfn "Waiting"
      sensor.Start()
      use engine = new SpeechRecognitionEngine(recognizer.Id)
      buildGrammar (engine, recognizer)
      engine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm,16000,16,1,32000,2,null))          
      
      // the token is only used to stop the loops
      let loops = Async.Parallel [listen engine; checkConnection()] 
      Async.RunSynchronously(loops, cancellationToken = source.Token) |> ignore       
      
      printfn("Stopped recognizer")
      sensor.Stop()        
  } 
  
  source  
    
use recognizer = //..
use sensor = //...
let source = startEngine recognizer sensor

// whenever you want to stop
source.Cancel()
One neat trick in F# is that you can pass a CancellationSource to the Async.Start() method and it will be automatically checked upon each nested async call - and if you write async blocks using recursion, you'll have a nice check every loop.

NihilCredo fucked around with this message at 16:27 on Dec 27, 2017

Mr Shiny Pants
Nov 12, 2012
I forgot to put "use" in front of the engine part. But yeah, that is good advice.

I came up with the following after some more finagling just after I posted:

code:
    let EngineController(recognizer:RecognizerInfo,sensor:KinectSensor) =
        async {
            use engine = new SpeechRecognitionEngine(recognizer.Id)
            try
                printfn "Waiting"
                sensor.Start()           
                buildGrammar (engine, recognizer)
                engine.SpeechRecognized.Add(fun x -> recognized x )
                engine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm,16000,16,1,32000,2,null))          
                Async.Start(async{ engine.RecognizeAsync(RecognizeMode.Multiple)})
                while sensor.Status = KinectStatus.Connected do
                    ()
                printfn("Stopped recognizer")
                engine.Dispose()
                sensor.Stop()
                sensor.Dispose()
            finally
                engine.RecognizeAsyncCancel()
                printfn("Stopped recognizer")
                engine.Dispose()
                sensor.Stop()
                sensor.Dispose()
        }
 Async.Start(EngineController(info,sensor),token)
I will try the synchronous version to see how that works out, I agree having to nest the asyncs for the async listener is a bit redundant.
One thing that is not clear, how do I get the reference to the passed in CancellationToken within the workflow? It seems Async.CancellationToken should do it, but if I cancel this it does not seem to trigger and I can't seem to evaluate a Token.IsCancellationRequested, only if I pass one into the function itself. It does run the finally block if I cancel the passed in one, so that seems ok for now.
Thanks guys :)

Edit: One more thing, the Async.RunSynchronously, is that ok to run inside another Async block? I always thought it was to start the "main" Async loop and the it should not be used deeply within the program because it blocks?

That is some nice code BTW, I especially like the check connection bit and feeding it into the Parallel bit. Man, I got some more learning to do.

Mr Shiny Pants fucked around with this message at 19:30 on Dec 27, 2017

LongSack
Jan 17, 2003

Anyone have any good leads on an open source (read “free”) printing library? I am mostly interested in FixedDocuments, since I am producing reports rather than more free form stuff. The only promising hit I got on google costs more than $2,000.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

LongSack posted:

Anyone have any good leads on an open source (read “free”) printing library? I am mostly interested in FixedDocuments, since I am producing reports rather than more free form stuff. The only promising hit I got on google costs more than $2,000.
I think you can just...

https://msdn.microsoft.com/en-us/library/system.windows.documents.fixeddocument.documentpaginator(v=vs.110).aspx
+
https://msdn.microsoft.com/en-us/library/system.windows.controls.printdialog.printdocument(v=vs.110).aspx

Xeom
Mar 16, 2007
.

Xeom fucked around with this message at 20:25 on Jan 1, 2018

LongSack
Jan 17, 2003


Yeah, but you have to compose the document with controls like grids, borders, list boxes/views, textblocks, etc., and if you want good looking output you have to do things like keep track of how high each line is so you know where to put the next one. It is drearily time consuming, thus my quest for something that would make it easier.

Adbot
ADBOT LOVES YOU

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
Does anyone know a clever way with ASP.NET Core to set cache headers only if an optional query parameter is set? For instance if the request is GET /foo?bar=baz I want to set a cache header like cache-control: private, max-age=31536000, but if the request is GET /foo I don't want a cache header.

You'd think the VaryByQueryKeys property on the ResponseCache attribute would have something to do with this, but as far as I can tell that's only used for server-side response caching, which I'm not interested in at the moment.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply