Ben
Best approach to SetThreadExecutionState
Hey!
I got an app that takes a periodic screenshot of open windows.
Some customers reported that after being idle for a while the screenshots seems to freeze.
Did some googling and it seems like once the OS/Monitor goes into idle/sleep state it stops rendering new frames (somewhat similar to what happens when you minimize a video and check its preview via winkey+tab).
This is the solution I found -
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate?redirectedfrom=MSDN
Using the above my goal is to keep the OS rendering new frames so the screenshots are up to date but I don't actually need the monitor itself to be visible.
I want to make sure I plan to use it correctly -
On the app main thread I'll run -
If I understood correctly, using
ES_CONTINUOUS
means I don't have to run this command periodically, as long as the thread is alive the state will remain.
ES_AWAYMODE_REQUIRED
is basically exactly what I'm looking for to keep rendering new frames but not to force active monitor.
ES_SYSTEM_REQUIRED
is this necessary?
And on application shutdown I'll run -
To revert changed settings.
Sounds correct?1 replies
❔ Naming Conventions N-Tier architecture, conflicts?
Hey!
Would like to hear additional feedbacks regarding this naming approach and a suggestion to solve conflicts.
The general naming idea is explained in details here -
https://softwareengineering.stackexchange.com/a/259840/429884
The summarize example would be (Taking User entity as example) -
*If the logic class gets too big we break it down to CQRS classes.
Following the convention above how would you avoid explicitly writing namespaces between the Model layer and the Business layer?
For example, you have this namespace in your Model layer -
ProjectName.Models.User
With a class called - User.cs
.
And this namespace in your Logic layer - ProjectName.Logic.User
with a class called - UserLogic.cs
.
You can't use User.cs
in UserLogic.cs
without specifying its entire namespace as User is part of the Logic namespace
What do you think?
thx!8 replies
❔ MemoryCache
Added
MemoryCache
to my dotnet 6 app.
Works fine on windows, ubuntu suddenly throws -
On library projects (that's referenced from the API) I need to install Microsoft.Extensions.Caching.Memory
in order to use MemoryCache
.
On the API itself I don't, is that cause of the additional Framework thats installed on the API project?
I've also checked earlier dotnet core versions, where I wasn't required to install this package, could that be a dotnet6 thing?2 replies
❔ MongoDB Update nested elements
MongoDB question,
I'm trying to add a property to all of my existing documents.
The thing is, my document has a property called
Events
, this property is an array of Event
that might have multiple or 0 elements.
I want to update all the nested elements of that property if exists.
This is what I tried which doesn't work -
First part I'm making sure that events isn't an empty array.
Second part I'm adding to all the child elements the NewPropertyTest
and initializing it to false.
My attempt fails with matchedCount:0
.
Any tips?15 replies
Download file, decompress and keep in memory
I have an endpoint that serves a gzipped .tsv file.
I want to download the file, decompress it and work on the data, without saving it on disk, keeping everything in memory.
Tried -
Which eventually contains gibberish so I'll guess the decompression doesn't work? any ideas?
If I download the file manually and extract it I get a folder with the .tsv file in it. maybe my issue is that I'm trying to read the string value of the folder and not its content?
Iv'e tried removing the AutoDecompression configuration and it seems to have the same result.
Thanks!
17 replies
LeetCode - Clone Graph [Answered]
Hey, trying to solve - https://leetcode.com/problems/clone-graph/
basically - question is to deep-clone a graph.
Could anyone helped me figure out why my solution isn't valid?
Error message -
You must return a copy of all the nodes in the original graph
My code -
6 replies
How to locally loadbalance threadsafe [Answered]
Hola,
I got an instance of a class that holds a list of end-points.
The class performs and awaits an http request to one of the end-points in the list.
The same instance of the class will be accessed async from multiple threads (about 300 times a second)
I need to round-robin load-balance the endpoints in the list.
Initially I thought of using a concurrentQueue and to dequeue/enqueue before and after every request. but the locking will hurt my performance as I have no need to wait for each request to finish before using the same end-point again..
I want that eventually within the 1 second, the 300 requests will be balanced between all the endpoints without delaying them.
I thought of using counter field as an index accessor, that I keep adjusting its value in a circle according to the end-points length.
what do you think? is there a better approach?
Simplified example -
19 replies
How would you design a solution to this problem?
unsure what would be the best approach -
I have a SQL table that stores SMS 3rd party providers.
Each provider support different protocols for its integration - (HTTP/SMPP).
According to the provider supported protocol it requires different parameters to be stored.
the HTTP providers stores -
1. URL endpoint
2. Api Key
The SMPP providers stores -
1. IpAddress
2. Port
3. Username
4. Password
Although they are different, they serve the same purpose therefore needs to exist in the same table.
So my question is, how would you handle this scenario both in the db and in the code?
Option 1 -
In the DB have a single table for
Provider
with such schema -
Protocol is an enum of HTTP/SMPP
And the Custom fields are nvarchar fields that are used according the the Protocol value.
I can select all the providers into a generic Provider
class.
Implement an IProvider
interface and concrete types - ProviderSMPP
and ProviderHTTP
Have a factory method that receives a list of Provider
and returns a list of IProvider
where I initialize each concrete type using a switch-case on the Protocol
field mapping the custom fields into its concrete values.
Option2 -
Break the Provider table.
Leaving the Provider table only with the shared fields, and create a relationship tables for ProviderSMPPCredentials
and ProviderHTTPCredentials
And join both tables?
What would you do?11 replies