C#

General discussions about the c# language, Squirrels | gist.gi...
Mar 7, 2022 22:28
@InVladimirPutinWeTrust .
Mar 7, 2022 22:28
Typically an HTTP request will timeout without a response and prematurely close the thread. So instead you run and await the sync task which essentially sleeps the thread until you receive the HTTP response.
Mar 6, 2022 17:11
there's no real point in wrapping an ASYNC method in a Task.Run... Essentially what ASYNC does is takes some work and processes it as resources are available on the current thread. That way you can run multiple tasks in parallel on one thread and have them not hold each other up, for say I/O waiting, etc.

What he's doing here is pushing the "real world work," off onto a secondary thread that isn't the main application thread--ideally to keep from hanging up any UI (if using Forms/WPF). Otherwise, this would essentially be a waste. The code would work exactly the samed with Task.Run() witho
Feb 20, 2022 09:19
@mr5 from what I've seen, they don't. The example provided with the MAUI preview has a basic setup where they define some styles for some text/button controls and the look is consistent across all platforms when you compile/run them (Android/Windows/iOS/etc).
Feb 20, 2022 04:46
My guess is this is due to the cross platform nature of MAUI, but this'll be a daunting task for themeability.
Feb 20, 2022 04:46
@mr5 okay so I got MAUI to compile and load up... I found out that styling, is basically from the ground up. There are no default styles, so you have to define everything yourself in the app.xaml as you mentioned prior in order for anything to be visible.
Feb 20, 2022 04:02
@mr5 Okay then that's not so bad... I guess it'll just be a bit of combing to find/create new styles and a theming system.
Feb 20, 2022 03:59
@mr5 is the formatting still the same as WPF?
Feb 20, 2022 03:56
@mr5 not much, but I have extensive experience with WPF and some experience styling WPF.
Feb 19, 2022 23:48
Does anyone know of any references for creating application themes with C# MAUI?
Jan 12, 2021 02:24
@default_noob_network ah it was you. Wrong Alex.
Jan 12, 2021 02:23
Someone did this the other day too.
Jan 12, 2021 02:23
@Freerey wrong Alex.
Dec 11, 2020 10:32
Yup. :(
Dec 11, 2020 10:29
@Wietlol right, which they could have just used a task like ReceiveAsync then it'd be awaitable.
Dec 11, 2020 10:25
So you get a TcpAsyncEventArgs object and subscribe a method to it's completed event.
Dec 11, 2020 10:24
It's weird... They went to all that trouble using the task/async/await pattern, then decided to use a whole event system for the sendasync function.
Dec 11, 2020 02:17
Trying to make a similar version to the Socket.ReceiveAsync(byte[], socketflags, cancellationtoken) function.
Dec 11, 2020 02:11
That returns a ValueTask<int> with the size of the data packet sent from SocketAsyncEventArgs().SendPacketsSendSize
Dec 11, 2020 02:10
Anyone know how to create an awaitable task out of Socket.SendAsync(byte[], socketflags, cancellationtoken)?
Dec 6, 2020 05:18
The ArrayPool<T> class in System.Buffers has a create() overload that takes two arguments, minLength and arraysPerBucket. Does anyone know the default # of arrays per bucket or how to set a good variable for it?
Dec 4, 2020 00:32
With ASYNC for networking... You can await read-calls and handle a single buffer for read calls. But with it being async, would I need to assign each client a secondary buffer for writing to the network stream? Or should I do an object pool of buffers to pull from?
Nov 28, 2020 09:22
@mr5 I think I've got it, thanks man.
Nov 28, 2020 09:11
(static methods).
Nov 28, 2020 09:11
Hm I might just do that then.
Nov 28, 2020 09:08
Network -> Received Data Packet -> Check Network Stream -> Deserialize Netwokr Stream Bytes to Struct. Struct Serialize to Bytes -> Send over Network Stream.
Nov 28, 2020 09:07
Like... a lot. It's for sending/receiving packet data.
Nov 28, 2020 09:06
@mr5 how would reflection affect performance though?
Nov 28, 2020 09:05
Wait, if I take them out of the struct I won't have access to the private unsafe fixed byte[] which is needed to serialize/deserialzie??
Nov 28, 2020 09:01
Which is perfectly reasonable.
Nov 28, 2020 09:00
So I guess I would need a constructor to create and deserialize a struct, then give it a serializer method and make the fields readonly.
Nov 28, 2020 08:59
Correct, seems like it. And of course it is discouraged to use mutable structs.
Nov 28, 2020 08:58
Or not at all.
Nov 28, 2020 08:58
At least with the [FieldOffset()] attribute.
Nov 28, 2020 08:57
Seems C# doesn't allow it though.
Nov 28, 2020 08:57
Yeah, typo.
Nov 28, 2020 08:56
Nope, I lied.
Nov 28, 2020 08:56
Ah well you could just do: public header { get; private set; }
Nov 28, 2020 08:53
Oh is it??
Nov 28, 2020 08:48
Fixed--the header and size variables should have been public: codereview.stackexchange.com/questions/252730/…
Nov 28, 2020 08:47
I'm an idiot.
Nov 28, 2020 08:47
Oh.... just realized.
Nov 28, 2020 08:47
Just add more variables, increase the size of the fixed byte[].
Nov 28, 2020 08:46
@mr5 nothing is missing, small example. 8 bytes, (4-byte alignment). 1 byte header, 4 byte int size, 3 bytes of padding.
Nov 28, 2020 08:33
@nyconing it's my code, not using someone else's API.
Nov 28, 2020 08:33
Then you can access the struct's public fields as normal after you've serialized/deserialized it.
Nov 28, 2020 08:32
@mr5 it's private purely to avoid direct unsafe access to it. So you call a method .Serialize(ref byte[] buff) which would just copy the unsafe byte data to the reference byte[]. Or other way around .Deserialize(ref byte[] buff) which would copy from the buffer to the unsafe byte[]. Pretty straight forward to avoid any weird usage cases.
Nov 28, 2020 08:22
Any alternatives?
Nov 28, 2020 08:19
I can do testing when a packet is received to check struct validity though.
Nov 28, 2020 08:18
@mr5 right it's a bit much... Deciding on whether the padding/alignment is necessary or not. If not I can shave off the padded bytes.