These are chat archives for AvaloniaUI/Avalonia

17th
Nov 2017
Jurjen Biewenga
@JurjenBiewenga
Nov 17 2017 12:27
@grokys I've been a bit busy with other projects however I've done the requested changes to the invalid char input
Steven Kirk
@grokys
Nov 17 2017 12:28
thanks @JurjenBiewenga - i've been busy with other stuff too!
will get that merged soon though
Jurjen Biewenga
@JurjenBiewenga
Nov 17 2017 12:30
Cool
I've had a question about DPI scaling in #1177, if you have a moment could you take a look at it?
Steven Kirk
@grokys
Nov 17 2017 18:01
whhahaahhht? it's magic!
Nikita Tsukanov
@kekekeks
Nov 17 2017 18:04
It uses some complex machinery involving ASP.NET Core, websockets, msbuild and our remote previewer
Steven Kirk
@grokys
Nov 17 2017 18:05
so basically, magic
Nikita Tsukanov
@kekekeks
Nov 17 2017 18:06
Yeah, I'd say this particular technology is sufficiently advanced
Steven Kirk
@grokys
Nov 17 2017 18:26
haha, i'd say so!
danwalmsley
@danwalmsley
Nov 17 2017 18:32
is this for vscode previewer?
Nikita Tsukanov
@kekekeks
Nov 17 2017 18:35
yep
Harry
@cra0zy
Nov 17 2017 18:40
you are crazy!!!
oh no wait
I am crazy
danwalmsley
@danwalmsley
Nov 17 2017 20:34
@kekekeks found a minor issue with completion engine
if you have anywhere in the XAML a property decalred with single quotes ie.
Property ='value'
completion will not work anywhere in the file after that point
Nikita Tsukanov
@kekekeks
Nov 17 2017 20:35
I guess I've ignored the fact that XML can use single quotes...
danwalmsley
@danwalmsley
Nov 17 2017 21:50
@jkoritzinsky regarding the sharpdx interop COM stuff
do you know how thread apartment state works with that?
iv tried porting this part of the debugger lib
but I don't really understand the apartment state thing
so I don't know how to make this stuff work correctly
Basically you can only call your COM object from threads that belong to the same apartment that it was created with
danwalmsley
@danwalmsley
Nov 17 2017 21:57
but when you running on linux
does that just mean any thread?
since it doesn't seem to be a thing on linx
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:00
Linux does not have a concept of COM apartment
So you can safely use any thread
danwalmsley
@danwalmsley
Nov 17 2017 22:02
so when running on windows
I need to actually use that code as is
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:03
Yep
danwalmsley
@danwalmsley
Nov 17 2017 22:03
and when on Linux then I use modified code
ok makes more sense
btw
that mtathread,cs
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:03
On Linux you can also have a separate thread
danwalmsley
@danwalmsley
Nov 17 2017 22:03
how do you read the run methods
is it just dispatching every call onto a new thread
or all calls onto the same thread?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:04
For the sake of unfying things
static Thread workThread;
I guess it has a specific thread with task queue
You can use your JobRunner class
danwalmsley
@danwalmsley
Nov 17 2017 22:05
hmm yeah I basically changed that code to use job runner
see here
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:06
And run it in a thread created with SetApartmentState (ApartmentState.MTA);
aren't all threads mta by default?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:06
if (Thread.CurrentThread != runner.MainThread)
I think you've misspelled == here
danwalmsley
@danwalmsley
Nov 17 2017 22:07
yeah it was ==
and nothing worked
it just locked up
and I made it !=
and 99% of debugger worked
it just freezes on property evaluation
so I really don't get it
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:07

and I made it !=

You've disabled your job runner by doing that

danwalmsley
@danwalmsley
Nov 17 2017 22:08
unless its called from a thread that isn't job runner
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:08
I think our main thread should be STAThread
And we might require that in the future
danwalmsley
@danwalmsley
Nov 17 2017 22:09
hmmm
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:09
That might be needed by some COM interop with win32 API
File dialogs and DirectX don't require any apartment
But there might be COM classes that do
Especially in clipboard/drag-n-drop area
danwalmsley
@danwalmsley
Nov 17 2017 22:10
how can I set avalonstudio main thread to sta thread?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:12
[STAThread] on Main
danwalmsley
@danwalmsley
Nov 17 2017 22:13
is it basically just trying to tell the difference between the main ui thread
and everything else?
?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:14
Not exactly
Some COM objects are not thread safe
Like, completely not thread safe
So you should only make calls to them from the same thread
And those objects require STA
You can have multiple STA threads
But each thread will have its own apartment
danwalmsley
@danwalmsley
Nov 17 2017 22:16
hmmm basically if I do this...
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
it works
but I need a way of doing the same thing without using apartments
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:17
I'd suggest to always push calls to the job runner
and make it run on MTA thread on windows
danwalmsley
@danwalmsley
Nov 17 2017 22:18
but there is obviously some calls that it needs to run just inline, otherwise you will get a race
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:18
I don't quite understand
Which calls and what do you mean by "inline"
BTW, set up a sync context on your job runner thread
so you could use async/await properly
danwalmsley
@danwalmsley
Nov 17 2017 22:20
how do I do that?
static void MtaRunner()
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            runner.RunLoop(new CancellationToken());
        }
???
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:21
inhertit from SynchronizationContext and override Send/Post
danwalmsley
@danwalmsley
Nov 17 2017 22:21
I'm way out of my depth now ;)
public class CustomSyncContext : SynchronizationContext
    {
        public override void Send(SendOrPostCallback d, object state)
        {
            base.Send(d, state);
        }

        public override void Post(SendOrPostCallback d, object state)
        {
            base.Post(d, state);
        }
    }
so this needs to post the callback onto the runner?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:28
Yep
danwalmsley
@danwalmsley
Nov 17 2017 22:28
what difference between post and send?
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:28
Send is supposed to wait for the call to complete
And you need to check if you are already on your runner thread
And invoke the delegate right away if you are
danwalmsley
@danwalmsley
Nov 17 2017 22:29
public class CustomSyncContext : SynchronizationContext
    {
        private JobRunner _runner;

        public CustomSyncContext (JobRunner runner)
        {
            _runner = runner;
        }

        public override void Send(SendOrPostCallback d, object state)
        {
            _runner.InvokeAsync(() => d(state)).Wait();            
        }

        public override void Post(SendOrPostCallback d, object state)
        {
            _runner.InvokeAsync(() => d(state));
        }
    }
Steven Kirk
@grokys
Nov 17 2017 22:31
@kekekeks have you had chance to look at AvaloniaUI/Avalonia#1270 yet? i just wonder if you think it's worth doing
basically it's trying to turn <Rectangle Fill="#ffff0000" Opacity="0.5"/> into <Rectangle Fill="#80ff0000"/>
danwalmsley
@danwalmsley
Nov 17 2017 22:32
does this look right?
public class CustomSyncContext : SynchronizationContext
    {
        private JobRunner _runner;

        public CustomSyncContext (JobRunner runner)
        {
            _runner = runner;
        }

        public override void Send(SendOrPostCallback d, object state)
        {
            if (Thread.CurrentThread == _runner.MainThread)
            {
                d(state);
            }
            else
            {
                _runner.InvokeAsync(() => d(state)).Wait();
            }
        }

        public override void Post(SendOrPostCallback d, object state)
        {
            _runner.InvokeAsync(() => d(state));
        }
    }
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:34
        public override void Send(SendOrPostCallback d, object state)
        {
            _runner.InvokeAsync(() => d(state)).Wait();            
        }
You need to invoke the delegate if you are on the right thread
there might be deadlocks otherwise
@grokys Sorry, it was a busy week
Steven Kirk
@grokys
Nov 17 2017 22:35
yeah no problem! i haven't had nearly enough time for avalonia recently :(
Nikita Tsukanov
@kekekeks
Nov 17 2017 22:35
if (Thread.CurrentThread == _runner.MainThread)
            {
                d(state);
            }
Yep, like that
Steven Kirk
@grokys
Nov 17 2017 22:35
i know how it is
was just a gentle reminder :)