|
For games like that a lot of the time the load times may be dominated by how mods interact with each other, where each one isn't the culprit specificaally but they're all trying to do "for each Thing" while also adding more Things. The other optionis if you can find the "load a mod" part of the code is to use dnspy or something like it and manually time how long it takes for each one. For 70 it's not infeasible to do that by hand. If you get real excited you could even edit the assembly on disk to make the game emit the times itself into a file.
|
# ? May 10, 2023 12:20 |
|
|
# ? Jun 8, 2024 09:31 |
|
Ran into a weird situation with aspnetcore deployed on premise IIS. It just wouldn’t update one environment variable. We tried deleting the website & app pool but still the environment variable (process scope) remained. We didn’t wanna restart the server, but what the hell?? Anyone knows what is up? The website was created using create/deploy iis thing on machine group task in in azure Devops pipeline.
|
# ? May 11, 2023 22:00 |
|
Is there a best practice for setting session data after you've logged a user in in ASP MVC 5 (yep, still on Framework)? Logging in invalidates the current session so anything added to it just gets dropped on the floor when the request is done, but I don't see a way to add to the new session before the next request, so I'm planning on stuffing some stuff in a short-lived cookie and adding it to the session on the next request which feels kinda gross and like there ought to be a better way.
|
# ? May 25, 2023 20:42 |
|
Hughmoris posted:I've never used perfview before but I'll give that a look, thanks! Beware, it's definitely a power user tool. It's super useful once you learn how to use it but there can be a really steep learning curve.
|
# ? May 25, 2023 20:51 |
|
Munkeymon posted:Is there a best practice for setting session data after you've logged a user in in ASP MVC 5 (yep, still on Framework)? Logging in invalidates the current session so anything added to it just gets dropped on the floor when the request is done, but I don't see a way to add to the new session before the next request, so I'm planning on stuffing some stuff in a short-lived cookie and adding it to the session on the next request which feels kinda gross and like there ought to be a better way. fwiw I recall that TempData by default works through a short-lived cookie so it's not like you're alone there
|
# ? May 30, 2023 07:26 |
|
I'm trying to create a background loop that periodically makes an HTTP request, but I'm not sure how to create the loop and continue with the execution while the loop is going.code:
It's probably a real basic thing about async/await, but it's something that I've never gotten.
|
# ? Jun 1, 2023 10:32 |
|
code:
code:
|
# ? Jun 1, 2023 11:05 |
|
If you want to do "endless" background work it should IMO be done on a separate thread, optionally with a CancellationToken so your main application is able to "nicely" get the background thread to stop when the app wants to exit. Async/await doesn't really come into play for this.
|
# ? Jun 1, 2023 11:46 |
|
You can also use the Timer class to raise an event every n seconds.
|
# ? Jun 1, 2023 12:39 |
|
SirViver posted:If you want to do "endless" background work it should IMO be done on a separate thread, optionally with a CancellationToken so your main application is able to "nicely" get the background thread to stop when the app wants to exit. Async/await doesn't really come into play for this. Using async is perfectly acceptable for endless background work loops, as long as the work loop itself uses async/await internally rather than doing blocking work. But yes, pass a CancellationToken to the method so it can be stopped. I use a pattern similar to this a lot to encapsulate such async background work within a class that can just simply be disposed to stop the background work: code:
biznatchio fucked around with this message at 16:02 on Jun 1, 2023 |
# ? Jun 1, 2023 15:57 |
|
Use the BackgroundService or IHostedService I think it’s in Microsoft.Extensions.Hosting
|
# ? Jun 1, 2023 20:58 |
|
Red Mike posted:
Why not await the background task?
|
# ? Jun 2, 2023 09:55 |
|
Kyte posted:Why not await the background task? Because then you can't do anything else on the awaiting thread until the background task finishes?
|
# ? Jun 2, 2023 10:16 |
|
Red Mike posted:
One thing to add is that the implementation of RunThingAsync matters. If it’s code wrapped in a Task.Run, you are probably fine. If it’s some regular async Task code, DoMoreStuff won’t start until the first await inside RunThingAsync is hit. code:
|
# ? Jun 2, 2023 14:28 |
|
Yeah, that's true, and also if any code before the first await throws an exception, that'll get thrown at your initial call site (instead of getting caught in the exception so you can check for it with Task.IsFaulted). code:
If instead nothing got thrown until "thing2", that other exception would not get thrown but instead cause the Task to become faulted (and as soon as/if you awaited the Task then, you'd get the exception). Lots of quirks and edge cases with all of this, you generally want to keep it simple and avoid the entire thing if you can (by using built-in things like IHostedService, or whatever framework you're using might have, etc).
|
# ? Jun 2, 2023 15:37 |
|
I really like async/await and Tasks but they can be really quirky. I’ve seen some pretty gnarly code bugs due to some of those. Relatedly, does anyone know any good analyzers for catching some of these issues?
|
# ? Jun 2, 2023 16:13 |
|
Jabor posted:Because then you can't do anything else on the awaiting thread until the background task finishes? No I mean like: code:
|
# ? Jun 3, 2023 21:45 |
|
What do you mean by unobserved task exceptions? I thought that back when async/await was introduced, tasks would no longer cause unhandled exceptions unless of course you're doing something nasty like async void.
|
# ? Jun 3, 2023 23:37 |
|
rarbatrol posted:What do you mean by unobserved task exceptions? I thought that back when async/await was introduced, tasks would no longer cause unhandled exceptions unless of course you're doing something nasty like async void. Maybe my knowledge is wrong but I'm pretty sure a faulted task eventually needs to be unwrapped and observed (whether via await or older mechanisms) or it'll eventually bubble up to the runtime? I know async void is dangerous because the task cannot be captured and therefore observed, but if you deliberately let a task go aren't got causing essentially the same behavior?
|
# ? Jun 4, 2023 06:37 |
|
Unobserved faulted tasks will cause the process to terminate in .Net Framework 4 -- at an indeterminate time because it can only happen when the Task is finalized, and that's at the mercy of the GC. Starting with .Net Framework 4.5, and all versions of .Net Core, they do not (unless you explicitly configure that you want the legacy behavior); but you can still be notified of them via the TaskScheduler.UnobservedTaskException event.
biznatchio fucked around with this message at 06:55 on Jun 4, 2023 |
# ? Jun 4, 2023 06:53 |
|
Kyte posted:No I mean like: While yes unobserved exceptions don't terminate any more, you probably don't want them to go unnoticed. IsFaulted isn't necessarily what you'd want to use, but awaiting also won't necessarily do the right thing. Generally, what you really want to do is make sure that any background task you start (i.e. the outermost Task) wraps all its internal logic in its own try/catch and handles any failure itself, if you're not going to be awaiting it. The same logic as you'd have for something like an event listener.
|
# ? Jun 4, 2023 15:03 |
|
I'm still transitioning some .NET Framework 4 projects over to .NET 6/7/etc, question about ASP.NET Core, it appears the ideas of Mvc and Api have been consolidated into one ControllerBase parent class, and for WebAPI functionality/behavior, you decorate the class with [ApiController]. These actions seems to want ActionResult or ActionResult<T> return types, so I can return T in the normal case, and e.g. return BadRequest when something goes wrong. This is fine so far, however it changes my controller action method signatures from this: C# code:
C# code:
epswing fucked around with this message at 18:43 on Jun 12, 2023 |
# ? Jun 12, 2023 18:39 |
|
I want to say that returning a type that inherits from ObjectResult will ensure you don't have to materialize the list & will stream it to the client, but I don't know if that's true or not and I can't seem to find any documentation on itC# code:
Potassium Problems fucked around with this message at 18:59 on Jun 12, 2023 |
# ? Jun 12, 2023 18:57 |
|
Potassium Problems posted:I want to say that returning a type that inherits from ObjectResult will ensure you don't have to materialize the list & will stream it to the client, but I don't know if that's true or not and I can't seem to find any documentation on it This is the generally recommended approach, with the caveat that if it's something like an IQueryable or an IEnumerable that does logic, you're going to have a fun time figuring out what's going wrong on error because it'll end up triggering deep in ASP.NET serialiser code. epswing posted:Wasn't there some value in streaming a response rather than having to buffer/realize everything before returning from the action? See what I said above about the errors though. Streaming a response is great in principle, but either way you always need to materialise your lists/etc as part of serialisation. The savings you'd have in not doing it before you return from the controller are tiny. If you need the performance and/or have something like a saved raw response you want to return (like e.g. if you're proxying a file you download from a CDN, or it's a mock API), use Response.Body/Response.StatusCode/etc to do your streaming and have your method return Task/void. But then that won't use any of the ASP.NET Core pipeline output formatters/etc. e: Also be aware that [ApiController] does quite a few changes, and not all are obvious. The docs have a list.
|
# ? Jun 12, 2023 22:07 |
|
Depending on the usage you might do with FileStreamResult from the File(stream) overload and possibly enabling EnableRangeProcessing.
|
# ? Jun 13, 2023 00:40 |
|
Are there any good resources on how people tend to use things like Records/Record Structs, Pattern Matching, and other newer language features in the real world? Everything I’ve seen so far is just toy examples (“Person(string name)” level stuff), but it’d be cool to see how people are using them to make things nicer. Semi-related, what are peoples thoughts on stuff like using small private types internally in a class to essentially replace Tuples or anonymous objects? Useful or just noise?
|
# ? Jun 13, 2023 18:02 |
|
For pattern matching: In functional languages it's extremely common to define custom union types to cover different cases whenever there are multiple options for something and then use pattern matching on them. Using them with enumerations would similarly probably be the most natural use in c#, but since I think c# enumerations are probably still a bit less ergonomic (you can't have enumerations of heterogenous types without using separately declared wrapper classes or something right?) and they tend to be used a lot more sparingly in languages like c# than union types in functional languages, that might make them less useful a lot of the time so I'm not sure I would necessarily reach for them as much as in a functional language? I'm not sure I would go out of my way to use it in c# if it doesn't seem natural. For declaring types vs tuples: Personally I feel like tuples can get pretty unreadable pretty quickly unless you're using them on like the next line so I'm a fan of declaring types mystes fucked around with this message at 18:17 on Jun 13, 2023 |
# ? Jun 13, 2023 18:08 |
|
I agree completely about tuples. Very useful for a quick throwaway type, but if you'll be needing them any more than in the next couple of lines, make a proper type for it.
|
# ? Jun 13, 2023 18:35 |
|
ChocolatePancake posted:I agree completely about tuples. Very useful for a quick throwaway type, but if you'll be needing them any more than in the next couple of lines, make a proper type for it. Echoing this verbatim. I've used Tuple for this kind of typing less and less over time and basically only use it now for something extremely ephemeral. Just make a proper type 99% of the time.
|
# ? Jun 13, 2023 18:39 |
|
If you have a tuple in a signature that’s getting too unwieldy, you can swap it out for a record struct and have things keep working pretty similarly.
|
# ? Jun 13, 2023 18:46 |
|
Canine Blues Arooo posted:Echoing this verbatim. I've used Tuple for this kind of typing less and less over time and basically only use it now for something extremely ephemeral. Just make a proper type 99% of the time. i don't use tuple in production code even if it's a very simple thing. i find code that uses proper types instead of tuple easier to read.
|
# ? Jun 13, 2023 19:13 |
|
Tuples are fantastic for returning multiple types from a single method. Now that you can name them there's no real reason to avoid it as a feature imo
|
# ? Jun 13, 2023 19:44 |
|
I don't use tuples for code that crosses file boundaries or anything public but I find it very useful for returning values from local or private functions as well as from Task.Run and cousins (ArcGIS addin development requires a looooooot of switching to the main CIM thread via QueuedTask.Run) where I can immediately unpack them into locals. Oh yeah they're also often more useful than anonymous types for LINQ queries that end in a First/FirstOrDefault. Basically anything that uses tuple unpacking, really.
|
# ? Jun 13, 2023 20:10 |
|
I can see the value in returning multiple values from local functions, but I haven't personally run into that use case myself. It's not so much that I avoid the feature, it's that creating an encapsulating type for all the return values is generally simple and more readable.
|
# ? Jun 13, 2023 20:12 |
|
This might be a bit of a dirty trick but you can have an awaiter for tuples like https://gist.github.com/jnm2/3660db29457d391a34151f764bfe6ef7. And then use it like: code:
|
# ? Jun 13, 2023 20:22 |
|
ChocolatePancake posted:I can see the value in returning multiple values from local functions, but I haven't personally run into that use case myself. I think this is my stance on it too, just stick ‘private record struct ButtFarter’ in front of the tuple declaration and it’s basically done. I’ve used some of the pattern matching stuff recently to allow me to create a single class that takes an IReport interface and uses type patterns to figure out which of the 4 inconsistent inheritors of reports something actually is and therefore where to find the email address of the person we should send it to, but I feel that’s just using a nice feature to paper over inconsistencies in the design where adding a real interface would be a much better solution (but harder because of the number of weird duplicate-but-slightly-different models that such a change would affect)
|
# ? Jun 13, 2023 20:35 |
|
The only thing I use tuples for any more is in operator ==C# code:
|
# ? Jun 13, 2023 23:16 |
|
Surprise T Rex posted:I think this is my stance on it too, just stick ‘private record struct ButtFarter’ in front of the tuple declaration and it’s basically done. that's the hard part though: naming your lovely type that exists just to bundle a couple of fields together
|
# ? Jun 14, 2023 01:37 |
|
redleader posted:that's the hard part though: naming your lovely type that exists just to bundle a couple of fields together This is precisely why I prefer a tuple like C# code:
|
# ? Jun 14, 2023 01:52 |
|
|
# ? Jun 8, 2024 09:31 |
|
Surprise T Rex posted:I think this is my stance on it too, just stick ‘private record struct ButtFarter’ in front of the tuple declaration and it’s basically done. this is more or less where ive used pattern matching the most. something like: code:
the top-level main also prevalent with newer codebases since its the new default I've found, and I've seen a few uses of global usings as well
|
# ? Jun 14, 2023 02:19 |