« first day (4115 days earlier)      last day (816 days later) » 

 
3 hours later…
mr5
8:32 AM
@Wietlol does runBlocking { launch { someAsnyc() } } prevents the host thread from freezing if someAsync() is long running operation?
 
8:46 AM
I dont know
does it look like I use async?
but you could also perhaps... not actually use the host thread
does launch { someAsync() } prevent the host thread from freezing if someAsync() is a long running CPU operation?
no
does async solve user interface from freezing?
no
 
mr5
@Wietlol yes
@Wietlol yes
 
hi all
 
you sure about that mr5?
 
mr5
9:12 AM
@Wietlol yes
 
then perhaps kotlin does a better job than c#
who would have guessed that
 
mr5
wat
no
C# is better in this regard
3
 
mr5
I can accomplish my goal using C# but not Kotlin
 
that sounds like a mr5 problem :p
 
mr5
9:21 AM
Y_Y
 
fridaaaay
 
calling an async function in C# that does not do an async call will still run on the caller's thread, so if you have a long running cpu operation, you will still freeze the caller's thread
 
F R I D A Y
 
thank God
 
@EdGzi for wat
 
 
1 hour later…
10:53 AM
@nyconing for Friday!
Is it possible to store a incremental number within the application?
e.g. I click a button, number goes up by +1
New number = 2
Next click = 3
and so on
When the application closes.. I need the last value saved
I am thinking of storing the number in a database
 
11:32 AM
Hii '
 
11:44 AM
return default!;
ew, so dirty
 
12:10 PM
I just had a damn heart attack
Visual Studio was telling me "cannot run when setup is in process" any time I tried opening it and I thought I had a damn virus again, which I would've had no idea where it came from
 
mr5
12:37 PM
@Wietlol why would you do that?
 
because "async prevents ui threads from freezing"
 
mr5
it does so long as it's an actual asynchronous process, i.e., it's running from another thread.
 
!!friday
 
mr5
collapser
 
1:00 PM
@EdGzi You need to store it somewhere - you can write it to the disk, you can write it in a database, you can probably store it in other places, too. However, by default, there is no way to save the value without something external to the application itself.
 
1:54 PM
Hi all
@mr5 How do you ensure something's running on its own thread?
Use something like await Task.Run(() => ....)?
 
mr5
@Alex you mean, how can I ensure that something that has been created on X thread is running on X thread and not on Y thread?
@Alex supposedly the usual case is that the other thread is always the main thread, then yes.
 
@mr5 Yes, so I have a thread X for something and then need to run something async on thread Y
Does calling an async method mean it's actually asynchronous? Sorry for the n00b question. In other words is await DoFooAsync() make it run on its own thread?
 
mr5
2:09 PM
@Alex no. Iirc, it needs to be in Task. async void would still execute on the same thread.
eh correction. Just had some tests. Marking the return type with Task or attaching with async does not guarantee it will run on a different thread.
To force it to run on a different thread, one could do Task.Run, Task.Factory.StartNew(), or await Task.Yield(); // next line is guaranteed to be async
 
Interesting. Thanks, mr5. Async stuff is such a mystery to me.
If it's running on the same thread, what's the benefit of having an awaitable method?
 
You've got to be really careful with things like "a different thread". What do you mean by that? Do you mean it will run concurrently, will it run in parallel, or will it block your current task?
 
2:25 PM
Good question. What's the diff among these: concurrently, parallel, block?
 
My understanding is that if you have very heavy async/await usage and you have a lot of I/O your app could technically be running on a single thread at a time because it only creates threads when it has work to do
Concurrent means both things progress at the same time.
Parallel means they actually do CPU work at the same time.
 
Thanks, that helps
 
Async/Await is, to my understanding, primarily for the first one. It lets you go away and do other things while your I/O tasks are stuck waiting on I/O.
 
So it's concurrent
 
mr5
@Alex that still remains a mystery to me. I have encountered this scenario, specifically on Xamarin.Android:
async void OnCreate(...)
{
	// On UI thread
	var permissionResult = await permissionService.Request(...)
}

async void OnPermissionResult(data)
{
	// On UI thread
	// will invoke once the user taps the dialog prompt
	permissionService.SetResult(data)
}
On OnCreate(), it did not freeze the UI thread while waiting for permissionService.Request()
@ThomasBoby I do often not care how it's going to be prioritize by the thread pool, as long as it's not going to block the main thread where the UI is residing.
In my understanding, the main thread is not included in the thread pool.
 
2:40 PM
Wow, C# is doing stuff behind the scenes for us and not always clear how it makes its decisions
 
I always do async Task ....
Well, it's a mystery to me anyway :)
 
I think that is basically up to the application framework. E.g. Xamarin.Android, WPF, .NET's "Host" all have something that is handling all the UI events and enabling async. I find it very difficult to understand async because I've never found an article explaining that part.
With the Host pattern, the "Main Thread" in debugger doesn't seem to do anything at all, it just waits for the application to end
 
Same thing here. I need a class on async
 
basically, you can drink your coffee and finish your conversation concurrently
taking a sip of coffee
saying a few words
taking a sip of coffee
saying more words
...
and you can walk and have a conversation in parallel
you can take steps and talk at the same time
 
2:44 PM
Nice analogies
 
concurrency is alternating, parallel is at the same time
 
Ohh
So for parallel, it uses the cores in the CPU
 
async is primarily neither
 
Okay, that adds a wrinkle to it
 
async is primarily sequential, which means that you finish one process before starting another
although, having your process be async, means that the outer scope can start your process concurrently or in parallel with other processes
 
And once you've got several async processes running, there's no longer any real distinction between them right? The threadpool will simply pick up any task that is ready to continue as long as it has free threads?
 
so, just have an async function with a few await calls in a row, can be concurrent, can be parallel and can be neither
they should have called it schrödinger instead of async :D
 
Hah! Where's the cat? :)
So is the .NET engine making those decisions?
It seems non-deterministic
 
@ThomasBoby any thread pool task executor can run the queued tasks in parallel
a single thread executor can only run them concurrently
 
mr5
Bill Gates do. He looks above the cloud and from there, he will decide if he's going to spawn a new thread for the Task or not :D
jk. I believe it's the logic set on the thread pool. I also believe, Task uses thread pool internally.
 
2:50 PM
.net runtime's root implementation uses (iirc) a fixed thread pool
 
Yes, the runtime decides. Because it isn't transparent, there is .ConfigureAwait(bool) in case you rely on finishing it in the same thread, like things being awaited from the UI thread.
 
however, different runtimes can make the behavior entirely different
 
@Squirrelkiller Finishing in the same thread context right, not quite the same as the same thread?
 
in .net the thread context is tightly coupled to the thread
so, although it is technically true that it binds to the context, the context is also bound to the thread, so it is a transitive binding to the thread
this is where Java's Loom comes in :D
 
Yes right, same context. In UI applications though, the UI thread has a context that stays the same.
 
2:53 PM
What's the diff b/w the thread and its context? Is it like an HTTP context, etc.?
 
In a webservice it's like, the request context or something
 
AHi guys, are we all C# lovers here ?
 
Yes like httpcontext
 
mr5
@Wietlol nice. I believe you are referring to dynamic thread pool right?
 
That makes sense
 
2:54 PM
@BlinkSun Yes, just ignore The Wietâ„¢
 
@mr5 no, lightweight threads
 
mr5
@Wietlol what does "transitive binding" means?
 
@BlinkSun I am, though I do JS/SQL too
@mr5 Was going to ask that next :)
 
mr5
Java's lightweight threads == C#'s managed thread ?
 
nope
 
2:56 PM
Nice to meet you all !
When did SOF implement a chat or m I late at this point :)
 
in Java, you have normal threads, which are similar to C# threads, which are just proxies to the OS threads
 
mr5
Kotlin coroutine == Java's lightweight threads?
 
If context is tied to a thread, if you configureawait(true) does it have to keep the thread alive (and counting against max threadpool threads)?
 
Chat has existed for a very long time, it just never took off as much as the main site :)
 
I'm using Alive because I have no idea what the right word is
 
mr5
2:56 PM
@Wietlol I thought, every threads on C# is managed thread, i.e., different from the OS threads
 
Alive is indeed the correct word
 
in Java, you also have lightweight threads, which are virtual threads
these can be attached and detached to an OS thread for processing
and they are extremely small objects so you can easily make millions of them
lightweight threads are more similar to Task in C#, but using the api of Thread
so, no async/await bs, just sequential
 
@mr5 it won't guarantee neither. These will inform sync context, that it should be long running, so go on other thread, but it possibly won't if you don't have enough free threads. You just signal you want to fork...
 
@mr5 kotlin's coroutines will probably be refactored to use the lightweight threads as implementation, but considering kotlin targets more than just Java, they cant use the lightweight threads 1:1
 
There's so much to async programming
 
mr5
3:00 PM
@ntohl well, I mean by "different thread" is a thread that is not the main thread but probably one of the threads in the thread pool.
 
Wow, that chat ll be my new duck debugger ;)
 
@mr5 still probably.
 
Where did you all learn these things? I've been programming for yrs and didn't pick up this kinda deep knowledge
 
mr5
so you're saying it could still run on the main thread?
 
@BlinkSun That is indeed our speciality :D
 
3:01 PM
blog.stephencleary.com is a good blog for Async/Await/Tasks/etc
3
 
@Alex and most of it is unnecessary :(
 
Yeah but it helps to know the under-the-hood work the runtime does
 
@mr5 C#'s managed threads are not 100% the same as OS threads, but they are one on one mapped
so, when you create a new Thread(), you also create a new OS thread and bind them together
 
So it's creating two threads?
 
basically, Thread is the api or a proxy of the OS threads
@Alex consider the following code
class MyThread {}
var x = new MyThread();
var y = new MyThread();
var z = new MyThread();
did I make 3 threads?
 
3:05 PM
Not sure. Thinking not
 
mr5
@Alex for me, I learn most of these things by creating my own GUI framework from "scratch". But I only retain the fundamentals in the long run. For language specifics, I would have forgotten them in just a few months.
 
well... technically yes, but not in the way you want "threads" to mean
so, yes, you do make two threads when doing new Thread(), but only one "processor thingy"
so windows will see 1 additional thread
the thread class in C# code is just a class that controls how the OS thread works
@Alex most of it is unnecessary knowledge for your everyday work
you just need to know how to use it, not how it works
 
@VLAZ I'll be storing the value in a database :D Thanks anyhow!
 
mr5
@ThomasBoby I feel like that guy is one member of the team behind C#'s Task
@Wietlol I need some advice.
 
And you ask Wietlol?
 
mr5
3:13 PM
yeah lol. People on Android room are bunch of snob to me unfortunately.
 
it better not have to do with coroutines
 
mr5
err it do
I was about to enter my question lol.
I am starting to hate Kotlin now.
 
and now you know it would be a mistake :D
 
mr5
If only I could use C#
 
if only
to be fair, Android is mostly the reason for your suffering
using C# or Kotlin wouldnt make a difference
 
3:16 PM
Kotlin is quite nice actually, but coroutines fucked me up too
 
mr5
it does actually. There's some magic on C#'s async/await
 
We were promised lots of snow here. Got just a dusting. I feel cheated
 
coroutines work quite well... it just still is absolutely useless
 
mr5
this is the magic I've found where I think Kotlin cannot do:
45 mins ago, by mr5
async void OnCreate(...)
{
	// On UI thread
	var permissionResult = await permissionService.Request(...)
}

async void OnPermissionResult(data)
{
	// On UI thread
	// will invoke once the user taps the dialog prompt
	permissionService.SetResult(data)
}
it does not block UI
 
async void
 
mr5
3:19 PM
:D
 
well... that is magic indeed
 
async void is for event handlers
 
mr5
it's an example only
just to emphasize where the magic happens
 
@Squirrelkiller it shouldnt be though
 
3:20 PM
Should those be using async Task?
 
if you can, then always
 
mr5
^
 
if you cant, then you might potentially be able to use an absolute abonimation of a workaround by using async void
 
Depends on the framework. Init methods in Blazor use async Task for example. For WPF commands OTOH, you need async void.
 
mr5
according to Stephen Cleary, the exception for async void is the event handlers.
 
3:21 PM
@Squirrelkiller Which is very annoying, can't remember what it was but I think it was causing me uncatchable exceptions in random places (WPF)
 
I wonder why. Didn't know there are places you shouldn't use async Task
 
It's more places you can't I think?
 
Well, firing an event isn't supposed to wait for whoever decided to put I/O on there
It's just an event, a thing that happens and is communicated to others.
If you want something that actually takes time, pass a callback or something.
 
So it's void in that case
 
@Alex there arent places you shouldnt use Task
but there are places where those tasks shouldnt be directly awaited
 
3:26 PM
Maybe you could cheat the system by making a public event Func<Task, MyEventArgs> OnSomethingHappened;
 
which is, for example, event handlers
it would be up to the event provider to decide how to deal with the handlers
 
So it's safe to do async Task everywhere, to be able to trace exceptions better
 
you could await them in sequence (so only one handler runs at one time)
you could await them concurrently/parallel (so all handlers finish before the event executor continues)
you could await in sequence in an unawaited task (so only one handler runs at one time, but the executor doesnt wait)
you could not await them at all
and probably more
the event executor could also queue your tasks in a special background thread pool so your event handlers have a lower priority
async Task everywhere, except when you cant
for example, WPF searches for functions by signature and demands that the init method returns void
so, you cant return Task or it will not find your init method
the same with (older) event handlers, which usually had a delegate that returns void
 
3:55 PM
@mr5 just a question though, did you read the tutorials on coroutines?
 
@mr5 what was the question you had?
 
mr5
hmm, I think now it's more about Android than Kotlin itself.
Also, I'm actually going to test now this code if it will not block the UI thread: `runBlocking { launch { longRunningOps() } }`
If you're curious, it's about WebView. Do you has te xp about Android's WebView?
 
I dont, but considering you use runBlocking, I assume your intention is to block the ui thread
 
mr5
4:02 PM
yeah, no
 
then why do you use runBlocking?
 
mr5
it's the only code I could find that would enable async on main thread
 
yes, but you dont want async on main thread
 
mr5
as I've told you, this would have work if it's C#
 
you want async on background thread, no?
 
mr5
4:04 PM
well, what I mean by "not blocking" the main thread, is that it should not freeze, but I do still want to "block" it.
wat
 
why do you want to block?
 
Wait so do you want to block the UI or not? I'm confused.
Because blocking the UI thread is what makes a UI freeze
 
mr5
cuz I have this scenario:
override shouldOverrideUrlLoading() : Boolean {
	val isHtml = runBlocking {
		launch {
			isHtmlContent() // Network call
		}
	}

	if (isHtml) {
		return false
	}

	// download it

	return true
}
 
ah
 
@GermanBernal Wtf is going on in that post can anyone read the code?
 
mr5
4:08 PM
@Squirrelkiller I tell you, "blocking" on C# does not freeze the UI thread.
 
@mr5 In C#, blocking the UI thread absolutely makes the UI freeze. That is a universal truth.
No matter the framework or language
If the UI doesn't freeze, you're not blocking the UI thread
 
Yes sorry really quick so I have a Purchase Orders and Purchase Items so I have a Edit view that I can edit the items, but I want to add new items at the same time
 
mr5
@Wietlol I've edited the code.
 
you probably have to extract that async call out of your non-async function
 
@GermanBernal Seems simple enough
Except I have never worked with MVC or Razor Pages, so no idea what to even look at
 
4:10 PM
if your function is a non-suspend, (or non-Task in C#) you are probably not meant to do long running tasks
 
right but for some reason I'm doing PUT in the controller and the new lines are not coming
the ID
 
(Also the code is literally not visible for me)
 
ARE IN 0
 
mr5
@Squirrelkiller ackchually, you wouldn't believe this until I could show you something about this C#'s non-freezing but blocking Task
 
if you choose to do so regardless, you choose to let the caller wait for you to finish
either extract it out, or intend to let your caller wait
 
4:11 PM
yes I know is a lot of steps
 
Is "Automation tests" another name for "unit tests"? it was mentioned in a technical test requirement.
 
not necessarily
but they are also not necessarily different
 
Anyone else seeing this?
 
unit test mean "test run in isolation"
 
@mshwf Unit, integration and e2e-test
 
4:12 PM
automation tests mean "test run automatically"
they are different classifications
unit tests might be automatic, but dont have to be
and automated tests might be in isolation, but dont have to be
@Squirrelkiller that is you
 
mr5
@Wietlol in mobile, it often means "UI testing"
 
I was asked to write a library , this was mentioned in the paper:
"Please, write automated tests for the library"
 
@mr5 no it doesnt
or imma smack some people
 
@Squirrelkiller Weird. Not here
 
mr5
I think on that case, the intructions meant unit testing that could run automatically
 
4:14 PM
@mshwf In many companies, writing tests isn't implied so they have to make it explicit.
 
@mshwf they probably mean unit tests
and want you to run those unit tests automatically before you deploy a new version so you cannot deploy without it being tested
 
@Wietlol CI/CD?
 
CI/CD can help you automate the unit testing, yes
 
mr5
@Wietlol search it on Google. Most of the results will direct you to "UI testing"
 
@mr5 Yes, this confused me, also directed me to QA testing (for example using selenium.)
 
4:17 PM
@mr5 not for me it aint
 
Did some research into UI testing with Selenium and special browser versions that plug into the unit tests. It's cool stuff though can be time consuming
 
Cypress > Selenium
 
I am still (kinda) looking for a tool to record user input so that I can use that to generate browser tests
 
@Wietlol A colleague has something like that, I just don't remember the name. It's available as a browser extension. ka... ca... cadan... kala... something in that direction.
Katalon Recorder
Basically you activate recording, and it makes a list of things happening, optionally including waiting times.
Usually you just use it as macro tool, but you might aswell use the list and convert it for another tool
 
basically, I dont want to export as C# MSTest for example
but instead to a data driven approach
I want to read the export and analyze it automatically
which is quite difficult to do on source code because I would have to parse and partially compile it
I see some "json" stuff in the list, but I'd have to google what they actually give me
 
4:31 PM
I'm surprised it exports as C# MSTest lol
 
For tests, I've found JSON to be the easiest tool to mock stuff. Deserialize to objects and run tests on them
 
How does MSTest do UI tests? Those coded UI tests I keep seeing and never actually look into?
 
well... if you use a web driver, you can send commands to the browser from your (separate) application
using this, you can just automate your browser interaction
either for testing purposes or workload automation
considering the test suite and the browser are separate, there is no restriction on what language the test suite is written in
you can write them in C#, Java, Python, Javascript, whatever
it doesnt matter, as long as you have a way to signal those commands to your browser
and generally speaking, you would use a language/environment where you have a library for the driver you want to use
for example, selenium
now, the primary advantage of this is that your test/automation can also be written/executed in any way you like
 
for me, I have my own hosted service that runs certain scripts
I want to generate a script using the recorded browser interaction
obviously, selenium and katalon wouldn't have support for my own tool
but if they can just expose the information, I can write my own code generator
it shouldnt be that difficult
the problem is that all recorders that I tried are either missing quite important information or simply dont expose the useful information and only allow you to export a generated result
 
4:37 PM
Selenium commands can be hard to determine. One trick was to use the browser Selenium extension to generate the code and then replicate in C#
 
the dynatrace json from katalon might do the job though
 
5:01 PM
Didn't know about Katalon. They have a free version too
 
 
6 hours later…
10:43 PM
generating the puppeteer json exports does seem to be fine information wise
 

« first day (4115 days earlier)      last day (816 days later) »