RDasher
RDasher
CC#
Created by RDasher on 12/19/2023 in #help
Advice for Multi Threading
Want some advice for multi-threading Basically, I had a Schedule Job running every 7 seconds, and what it would do is, is pick up 5 items in a queue that had to be done, and processed them one by one, this was slow, and considering we had 900,000 items in the queue, we decided that multithreading was the way to go. The way we implemented is, we still have the item count at 5, but we have 16 threads, so from our database, we request 5 x 16 = 80 items. and then partition the big list of 80 items into 16 lists of 5 items each, which are then executed by each thread, now this was a massive improvement, we went from 10k records a day to just over 150k records a day We're on the tail end of this intensive first time task, we have just over 7k items remaining before we're done with our queue (that had 900k items) But in the future, we might be getting another 500k-1 million items in the queue that will need to be processed. Any suggestions for how I can improve this logic/best practices for partitioning and allocating items to threads One idea was, that I don't split the list at all, and each thread simply picks an item from a global list whenever it is free. Though I have no idea how to do this without two threads picking the same items at the same time.
15 replies
CC#
Created by RDasher on 10/25/2023 in #help
❔ Running .NET Framework Project off of command line
I primarily work with .NET core, and it is a breeze with dotnet But I've recently come across a .NET Framework web project, and I wanted to know if it was possible to build and run it off the command line Firstly I have managed to build it using msbuild. and I know I can host using IIS, so in theory, I can write a simple batch file to: 1) Build the project 2) Copy the contents of the build to the web directory 3) Start the IIS site But I wanted to know if there was a way to do this without going through this like I can with dotnet for .NET Core
41 replies
CC#
Created by RDasher on 3/23/2023 in #help
❔ IIS Express Modifying DLLs
Basically, we have a website that is hosted on IIS, and what happens is that during application startup, we record the last modified date of the DLL files and save that as our last "Update date" And then proceed to display that as the update date to all users Issue came, when for some reason IIS express started modifying the DLLs at in early morning hours This whole process is getting scrapped and replaced cause it's awful and shouldn't have been implemented in the first place, but I'm curious, why does IIS express modify the DLLs?
10 replies
CC#
Created by RDasher on 1/28/2023 in #help
❔ ✅ Generic-ify adding scoped for entities
So I've created a repository pattern based logic of dealing with DB entities. Basically I can do IRepository<WhateverClassIWant>() to connect the corresponding entity in the database, issue with this is that on startup, I need to add scopped to all my class:
services.AddScoped<IRepository<Product>, Repository<Product>>();
services.AddScoped<IRepository<User>, Repository<User>>();
services.AddScoped<IRepository<Order>, Repository<Order>>();
services.AddScoped<IRepository<Product>, Repository<Product>>();
services.AddScoped<IRepository<User>, Repository<User>>();
services.AddScoped<IRepository<Order>, Repository<Order>>();
All the above models inherit from a base class called BaseEntity that has some core fields such as Id, CreatedOn, UpdatedOn, etc I want to make this services.AddScoped action generic so I don't need to define this every time I create a new database entity. This is my current status which is not working:
foreach (BaseEntity BaseType in Assembly.GetAssembly(typeof(BaseEntity)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(BaseEntity))))
{
services.AddScoped <IRepository<(BaseEntity)BaseType>, Repository <(BaseEntity)BaseType>> ();
}
foreach (BaseEntity BaseType in Assembly.GetAssembly(typeof(BaseEntity)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(BaseEntity))))
{
services.AddScoped <IRepository<(BaseEntity)BaseType>, Repository <(BaseEntity)BaseType>> ();
}
Directly feeding BaseType is not working either, since IRepository requires a type of T : BaseEntity, not a type of type type
17 replies
CC#
Created by RDasher on 1/18/2023 in #help
❔ MongoDB: Cache conventions
Hello, I'm trying to figure out what's a better convention for caching records in my API application. What I currently do:
public IEnumerable<T> Table(FilterDefinition<T> _Filter) => _DBSet.Find(_Filter).ToList();
public IEnumerable<T> Table(FilterDefinition<T> _Filter) => _DBSet.Find(_Filter).ToList();
Depending on the filters I have selected (list search page, finding a specific record, etc), I send that as a filter definition into the MongoDb<T>.Find(_Filter) method. Now for the sake of caching, these filter definitions would not work if I'm correct, so I would need to first load all records into Cache, then do filtering. What's the recommended way of doing this? >Create Filter Query -> Search Db -> Get Results >Get All Results -> Create Filter Query -> Query Results
3 replies
CC#
Created by RDasher on 1/18/2023 in #help
✅ CORS: Cross-Origin Request Blocked
Hello, I'm trying to figure out how to configure CORS on my .NET Web Api Application. The Api Application is hosted on localhost:5000, while the ReactJS Frontend is hosted on localhost:3000.
public static void InitializeCORS(this IServiceCollection services)
{
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("http://localhost:3000/*").AllowAnyHeader().AllowAnyMethod();
});
});
}
public static void InitializeCORS(this IServiceCollection services)
{
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("http://localhost:3000/*").AllowAnyHeader().AllowAnyMethod();
});
});
}
Also have defined Application to use Cors in Program.cs
app.UseCors();
app.UseCors();
I've followed this from MSDN: https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-7.0
85 replies
CC#
Created by RDasher on 1/14/2023 in #help
✅ MongoDB Document Name
40 replies
CC#
Created by RDasher on 12/17/2022 in #help
✅ Reliably kill .NET processes
10 replies
CC#
Created by RDasher on 12/15/2022 in #help
✅ Adding class to .csproj file
Linux and command line user here. Is there an easier way to add a class to a .csproj file other than manually opening it in an editor and typing it out? are there some CLI tools to make this easier? or am I just gonna have to make my own? OS: Linux Editor: Visual Studio Code .NET Version: 7.0.1
14 replies