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.
 
  • Locked thread
Shaggar
Apr 26, 2006
I mean it looks like you're trying to do a modal dialog in the weirdest way possible. like maybe the compiler is optimizing the loop so it doesn't send the updates to the other "window" until its done processing the loop? idk. weird as gently caress dude. also maybe put ActiveWindow = New GenericWaitWindow in the constructor or something maybe cause that's whats probably null when you're calling that delegate.

Like you're running the long running task on the main ui thread and then spawning a second ui thread to display the wait dialog. that's backwards as hell.

what you want to do is run the long running task in a background thread and leave the main UI thread working and disable input when the thing kicks off and re-enable it/show results when complete. So when a user clicks a button you disable input and then fire off the long running task in a background thread with a callback that re-enables input and shows results. you can also pass a reference to a progress property to the long running task so it can send updates while it works back to the ui thread.

Adbot
ADBOT LOVES YOU

MeruFM
Jul 27, 2010
why would you disable the main UI waiting for the long running thread to finish

why not just put everything on 1 thread at that point

zeekner
Jul 14, 2007

blocking ui thread is a bad thing on any UI framework, that's what triggers the "not responding" status

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
DO NOT BLOCK THE UI THREAD

Shaggar
Apr 26, 2006

MeruFM posted:

why would you disable the main UI waiting for the long running thread to finish

why not just put everything on 1 thread at that point

I didn't say to disable the main thread I said to disable input on the main thread. the user can still interact and do stuff and maybe go to other parts of the app, they just cant relaunch that specific task (which is the point of the modal dialog)

Shaggar
Apr 26, 2006
like you could have a cancel button and progress bar in there or whatever as well, but the point is you disable specific input to prevent resubmission of the task. you don't block the main thread and you don't block the main thread and spawn a separate ui thread (what gently caress them is currently doing)

MeruFM
Jul 27, 2010
ok
when i saw disable input, i thought you meant just freeze the main UI

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
oh god how the gently caress do I do multithreading/async

is there a book

help

raruler
Oct 5, 2003

“Here lies a toppled god —
His fall was not a small one.
We did but build his pedestal,
A narrow and a tall one.”

uncurable mlady posted:

oh god how the gently caress do I do multithreading/async

is there a book

help

yes, it's called the Kama Sutra, because you are getting hosed 6 ways to sunday

Bloody
Mar 3, 2013

Parallel.ForEach

Shaggar
Apr 26, 2006

uncurable mlady posted:

oh god how the gently caress do I do multithreading/async

is there a book

help

this is a pretty decent example:
http://msdn.microsoft.com/en-us/library/hh191443.aspx

async is not necessarily multithreading, it just lets the compiler know it can continue other work while waiting for the result of the async method to return. it takes a little getting used to but it ends up being way easier to use than threads and just as effective (if not more so because threads are big objects)

the Task async pattern is kind of similar to futures in that you fire off an async method that returns SomeType and instead of SomeType you get back a Task<SomeType> you can continue doing parallel work after your call to the async method. then once you've done all your work (or fired off all the async methods you wanted) you can then await the result of the task.

Basically, make all your methods async. Then when you are calling your async methods, ask "Do I need this result before the next statement?" if not, collect the Task from the method and continue on. If you do need the result for the next statement, or if you have the Task and you have done other work and now you need the result for the next statement, await the Task's completion. Czech out the example in that msdn doc

its turtles all the way down.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
please read a book

coffeetable fucked around with this message at 22:56 on Jul 18, 2014

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

uncurable mlady posted:

oh god how the gently caress do I do multithreading/async

is there a book

help
The Little Book of Semaphores is great for practicing how you reason about concurrent code, but its very "low level" and you'll want a language-specific book as well to introduce you to yr language's constructs. if you're working in java, Java: Concurrency in Practice is v good, even if it's missing the fork/join stuff that turned up in Java 7.

and while checking that i got the names right for those, ive just spotted Seven Concurrency Models in Seven Weeks which is deffo going on my reading list

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

coffeetable posted:

The Little Book of Semaphores is great for practicing how you reason about concurrent code, but its very "low level" and you'll want a language-specific book as well to introduce you to yr language's constructs. if you're working in java, Java: Concurrency in Practice is v good, even if it's missing the fork/join stuff that turned up in Java 7.

and while checking that i got the names right for those, ive just spotted Seven Concurrency Models in Seven Weeks which is deffo going on my reading list

thanks, this is useful

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

coffeetable posted:

please read a book

pls keep your personal vendetta against me in pms and out of the threads thnx

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

coffeetable posted:

The Little Book of Semaphores is great for practicing how you reason about concurrent code, but its very "low level" and you'll want a language-specific book as well to introduce you to yr language's constructs. if you're working in java, Java: Concurrency in Practice is v good, even if it's missing the fork/join stuff that turned up in Java 7.

and while checking that i got the names right for those, ive just spotted Seven Concurrency Models in Seven Weeks which is deffo going on my reading list

Thanks for the useful post :bravo:

Pittsburgh Fentanyl Cloud
Apr 7, 2003


gently caress them posted:

pls keep your personal vendetta against me in pms and out of the threads thnx

Maybe you should try reading a book? lol

gonadic io
Feb 16, 2011

>>=

Bloody posted:

Parallel.ForEach

Mozi
Apr 4, 2004

Forms change so fast
Time is moving past
Memory is smoke
Gonna get wider when I die
Nap Ghost
use scala

double sulk
Jul 2, 2010

It's good that Mozilla brought Steve Klabnik in full time since he's certainly putting in the work on the Rust docs. I'd like to spend some time with it but it still seems pretty unstable at this point and I have another few hundred pages of Programming in Scala to cover.

Mozi posted:

use scala

I've been feeling pretty apathetic about it (Scala) lately though, which is certainly not good considering it's my current job's primary language. I feel like it's not a great thing when a programming language requires me to have a PhD and/or be completely insane to be able to contribute anything to a majority of libraries being developed.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

uncurable mlady posted:

oh god how the gently caress do I do multithreading/async

is there a book

help

ljw1004 please


its like ur batsignal

Malcolm XML fucked around with this message at 00:43 on Jul 19, 2014

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shaggar posted:

this is a pretty decent example:
http://msdn.microsoft.com/en-us/library/hh191443.aspx

async is not necessarily multithreading, it just lets the compiler know it can continue other work while waiting for the result of the async method to return. it takes a little getting used to but it ends up being way easier to use than threads and just as effective (if not more so because threads are big objects)

the Task async pattern is kind of similar to futures in that you fire off an async method that returns SomeType and instead of SomeType you get back a Task<SomeType> you can continue doing parallel work after your call to the async method. then once you've done all your work (or fired off all the async methods you wanted) you can then await the result of the task.

Basically, make all your methods async. Then when you are calling your async methods, ask "Do I need this result before the next statement?" if not, collect the Task from the method and continue on. If you do need the result for the next statement, or if you have the Task and you have done other work and now you need the result for the next statement, await the Task's completion. Czech out the example in that msdn doc

its turtles all the way down.

no don't


async makes functions slower due to an implicit state machine so only use it if u need to use await

also it's usually better to split validation and async body to allow for fast failure

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
but otherwise go hog iwld and watch the debugger attempt to keep up with that poo poo

Shaggar
Apr 26, 2006
Microsoft says 2 use async for everything and newer versions mvc are all async

Bloody
Mar 3, 2013

wish your posts were async and lazily evaluated so i could choose to never await them!

~Coxy
Dec 9, 2003

R.I.P. Inter-OS Sass - b.2000AD d.2003AD

prefect posted:

i think resharper wants you to use var by default

actually they admitted that it was a mistake and never intended to be on by default

but I do like var anyway so it's all good

tef
May 30, 2004

-> some l-system crap ->

coffeetable posted:

and while checking that i got the names right for those, ive just spotted Seven Concurrency Models in Seven Weeks which is deffo going on my reading list


http://pragprog.com/book/pb7con/seven-concurrency-models-in-seven-weeks

oh god this is a real thing

here are some real concurrency models

- share everything and hope your locks work but they won't because you're an idiot

- share nothing, but oh no ~latency~ from copying poo poo who cares, get it working first and then try and build a broken locking version

fritz
Jul 26, 2003

coffeetable posted:

and while checking that i got the names right for those, ive just spotted Seven Concurrency Models in Seven Weeks which is deffo going on my reading list

88 bugs in 44 threads

Bloody
Mar 3, 2013

fritz posted:

88 bugs in 44 threads

8bs48nigt hrdsea4u

Nomnom Cookie
Aug 30, 2009



tef posted:

- share nothing, but oh no ~latency~ from copying poo poo who cares, get it working first and then try and build a broken locking version

or just avoid the copies and declare "hell be upon ye who shall modify thy messages after ye send"

Notorious b.s.d.
Jan 25, 2003

by Reene

Kevin Mitnick P.E. posted:

or just avoid the copies and declare "hell be upon ye who shall modify thy messages after ye send"

this is just a really biblical way to describe the first system:

quote:

- share everything and hope your locks work but they won't because you're an idiot

Notorious b.s.d.
Jan 25, 2003

by Reene
"hell be upon ye who shall... " rules fall down the day you make a new hire. expecting people to suss out and then observe convention is a terrible way to build software

you either enforce your invariants or you have none

BONGHITZ
Jan 1, 1970

the old man told me to make it const... i didn't listen

gonadic io
Feb 16, 2011

>>=

Malcolm XML posted:

no don't


async makes functions slower due to an implicit state machine so only use it if u need to use await

also it's usually better to split validation and async body to allow for fast failure

this is premature optimisation and bad advice imo, chances are that being buggy is way worse than being a little slower

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

tef posted:

http://pragprog.com/book/pb7con/seven-concurrency-models-in-seven-weeks

oh god this is a real thing

here are some real concurrency models

- share everything and hope your locks work but they won't because you're an idiot

- share nothing, but oh no ~latency~ from copying poo poo who cares, get it working first and then try and build a broken locking version
you missed
- eh? what's a concurrency model? i just rerun the tests

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shaggar posted:

Microsoft says 2 use async for everything and newer versions mvc are all async


AlsoD posted:

this is premature optimisation and bad advice imo, chances are that being buggy is way worse than being a little slower

no its basically: do u need to use await in the method? slap async

otherwise return the task directly and ur method is still awaitable by an async method

if u need to use await more than once or need to do processing on the result of a task use async

it's a very specific but pretty common thing but it helps debugging

like u have
code:
 public Task<int> DoSomethingAsync(int i) { 
 // validation
if( i < 0) { throw FuckYou() ;}

return DoSomethingAsyncImpl(i);
}

private async Task<int> DoSomethingAsyncImpl(int i) { whatever}

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

AlsoD posted:

this is premature optimisation and bad advice imo, chances are that being buggy is way worse than being a little slower

the compiler will bitch at u about async with no awaits and its for exactly this reason

distortion park
Apr 25, 2011


just checking: does setting variables from config files always look kind of crap? i've got a load of fields and a big stream reader method setting them one by one as it goes through the file

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

pointsofdata posted:

just checking: does setting variables from config files always look kind of crap? i've got a load of fields and a big stream reader method setting them one by one as it goes through the file
use a library

Adbot
ADBOT LOVES YOU

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band

pointsofdata posted:

just checking: does setting variables from config files always look kind of crap? i've got a load of fields and a big stream reader method setting them one by one as it goes through the file

isn't there something that just sucks up a config file and gives you a data structure? i like that kind of thing

  • Locked thread