Alex
Alex
CC#
Created by Alex on 5/31/2024 in #help
Performance Advice
Hello there! I'm currently developing some software for a certain company so I can't share that many details, however, I'd still appreciate if some people helped me thinking about a solution for this: I have two programs, the main one and a secondary one, both written in C#. The main one is x64 whilst the secondary one is x86 due to internal dependencies written in C and compiled for x86. The only way I've found to connect these two are for both of them to be compiled and for a new Process to be called with command line arguments asking for responses on the x86 program. This happens every time an action is performed in the x64 program, and it ends up delaying it for a second or so. This is not a big deal for the end-users (It's an internal tool and the maintenance team, which this is designed for, has expressed satisfaction with how it's coming along) but it makes a difference to me. I'm quite perfectionist when it comes to most things. I have tested everything modularly and the operation that takes the most time, as expected, is the process being started. I have complete access to the code of the x86 program, as I'm the one that wrote it too. My objective is to cut down on the time it takes for this action to be completed, and it seems like the issue is Process.Start. My intuitive solution is to implement a loop on the x86 that keeps it running and accepting commands and giving outputs, but that will take a lot of processing power due to what it is doing, so I'd like to keep it as a last resort. Does anyone have any different ideas? Any inputs/knowledge/advice is appreciated! I don't know everything so I've probably missed something. Thanks in advance!
19 replies
CC#
Created by Alex on 4/9/2024 in #help
Adding program to Local Machine Registry
Hey there! I've been trying to add a program to the local machine registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run so that it runs on boot, but this seemingly isn't working. I have administrator privileges.
// Get the key to be added to the Windows Registry
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
string bootScriptFilepath = Path.Combine(serverSection.AddSection(ScriptsSectionName).SectionFullPath, BootScriptName);

if (serverSection.GetFirstDocumentNamed("boot.bat") == null)
{
// Create the .bat file to be added to the Windows Registry
string[] command = BuildStringForStartupRegistryCommand(serverSection.SimpleName).Split('\n');
FileUtils.DumpToFile(bootScriptFilepath, command.ToList().Select(s => s.Trim()).ToList());
}

// Add the key to the Windows Registry if it doesn't already exist
if (key != null && !IsServerInRegistry(serverSection))
{
key.SetValue("Glowberry-" + serverSection.SimpleName, bootScriptFilepath);
key.Flush();
key.Close();
return true;
}

return false;
// Get the key to be added to the Windows Registry
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
string bootScriptFilepath = Path.Combine(serverSection.AddSection(ScriptsSectionName).SectionFullPath, BootScriptName);

if (serverSection.GetFirstDocumentNamed("boot.bat") == null)
{
// Create the .bat file to be added to the Windows Registry
string[] command = BuildStringForStartupRegistryCommand(serverSection.SimpleName).Split('\n');
FileUtils.DumpToFile(bootScriptFilepath, command.ToList().Select(s => s.Trim()).ToList());
}

// Add the key to the Windows Registry if it doesn't already exist
if (key != null && !IsServerInRegistry(serverSection))
{
key.SetValue("Glowberry-" + serverSection.SimpleName, bootScriptFilepath);
key.Flush();
key.Close();
return true;
}

return false;
That's the code I'm using; There's more that checks if it is in and stuff, and whilst key.GetValue() returns an actual value and not null, the entry isn't added to regedit, and my program doesn't actually start on boot. Help?
2 replies
CC#
Created by Alex on 10/31/2023 in #help
✅ SQLConnection and queries to the database
Hey there! I've been having this problem lately with something i'm writing, which essentially boils down to the following code:
String conn = $@"Server={server};Database={database};Trusted_Connection=True;";
this.Connection = new SqlConnection(connectionString);
this.Connection.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Alunos", this.Connection);
SqlDataReader reader = cmd.ExecuteReader();
String conn = $@"Server={server};Database={database};Trusted_Connection=True;";
this.Connection = new SqlConnection(connectionString);
this.Connection.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Alunos", this.Connection);
SqlDataReader reader = cmd.ExecuteReader();
When I run this, it seems to just not find my Alunos table, and I end up having to write [{database}].[dbo].[Alunos] even though I had specified that I wanted to start out with a database in my connection string. What am I doing wrong here? I don't want to have to write my queries with dbo.(...); I'd rather just switch to the database I want at runtime and then query a table directly 😅
33 replies
CC#
Created by Alex on 7/29/2023 in #help
❔ Jetbrains Rider - Designer Stuck on Loading
Whilst trying to open any form designer in any computer, my project seems to get stuck on loading forever. This is happening on Rider 2023, latest. https://github.com/MrKelpy/MCSMLauncher Any help? I'm not sure what's causing this, but I can't go on without it.
10 replies
CC#
Created by Alex on 4/17/2023 in #help
❔ Processes and Async
How can I recreate this with Async? (BeginOutputReads and such)
// If an error happens, prints it and returns 1.
if (proc.StandardError.Peek() != -1)
{
Console.Clear(); Console.ForeColor = Color.Firebrick;

while (!proc.StandardError.EndOfStream)
Console.AppendText(Logging.LOGGER.Error(await proc.StandardError.ReadLineAsync()) + Environment.NewLine);

return 1;
}

while (!proc.StandardOutput.EndOfStream)
{
// Read the output line by line, and wait for the "Done" line to be printed.
await Task.Delay(100);

string line = await proc.StandardOutput.ReadLineAsync();
Logging.LOGGER.Info(line);
if (line != null && !line.Contains("Done")) continue;

Console.AppendText(Logging.LOGGER.Info("Server is DONE, killing process") + Environment.NewLine);
break;
}
// If an error happens, prints it and returns 1.
if (proc.StandardError.Peek() != -1)
{
Console.Clear(); Console.ForeColor = Color.Firebrick;

while (!proc.StandardError.EndOfStream)
Console.AppendText(Logging.LOGGER.Error(await proc.StandardError.ReadLineAsync()) + Environment.NewLine);

return 1;
}

while (!proc.StandardOutput.EndOfStream)
{
// Read the output line by line, and wait for the "Done" line to be printed.
await Task.Delay(100);

string line = await proc.StandardOutput.ReadLineAsync();
Logging.LOGGER.Info(line);
if (line != null && !line.Contains("Done")) continue;

Console.AppendText(Logging.LOGGER.Info("Server is DONE, killing process") + Environment.NewLine);
break;
}
127 replies
CC#
Created by Alex on 11/26/2022 in #help
❔ Invalid Data Exception when extracting files
I am getting a System.IO.InvalidDataException: Found invalid data while decoding. error while running this line...
ZipFile.ExtractToDirectory(InternalFileManager.INSTANCE.QueryFilePath(filename), InternalFileManager.INSTANCE.QueryDirectoryPath("tmp", true));
ZipFile.ExtractToDirectory(InternalFileManager.INSTANCE.QueryFilePath(filename), InternalFileManager.INSTANCE.QueryDirectoryPath("tmp", true));
Though I have no idea why. The file that I am extracting is one that has been downloaded, with the following code: https://pastecode.io/s/2rhskczr Is there something i'm missing here?
22 replies
CC#
Created by Alex on 9/19/2022 in #help
When to use Databases vs Filesystem Storage
I have a question about the title: I've gone around the internet looking for answers in this, but I haven't found a concrete one. I understand that Filesystem Storage is supposed to be "temporary", as in saving files to the client, and a database is supposed to be permament, storing the files in the database hosted in a server, and having everything go through software in the server that accesses the database and brings back a response. But why should it be done this way, and instead, why can't the stuff be stored in the server's filesystem storage, permanently? It seems simpler, and the answer can't just be "due to performance and speed", can it?
25 replies