Gibbo
Gibbo
CC#
Created by Gibbo on 9/5/2023 in #help
❔ FTP Uploading Files bigger than 2GB
this is quite a difficult one to put to paper, but i have teams/discord and if need me and I can live share the code. this may be an easier option in my WinForms Application I have the ability to upload using the WinSCP API. now part of this is its generates a file list so that if I push the repository through again it will only upload new files or modified files. to do this it puts the whole file in memory to generate some kind of checksum of the file using File Information (I'm still not sure how this code works as I have used some of it from a Game Updater. when I wasn't using files over 2GB this was working flawlessly, how ever I'm now moving on to push larger files I'm reaching the 2GB limit with File.ReadAllBytes (and the 32bit windows memory issue) so some research suggests I should be using File Stream, so I've modified my code for that but now its not copying the byte data over correctly. I tried a couple 5gb+ files and it only wrote between 1gb and 1.7gb on the FTP server. I think it will be something completely obvious I but I'm loosing the will to live lol!!!!!
public byte[] FileToByteArray(string fileName)
{
byte[] fileData = null;

using (FileStream fs = File.OpenRead(fileName))
{
using (BinaryReader binaryReader = new BinaryReader(fs))
{
fileData = binaryReader.ReadBytes((int)fs.Length);
}
}
return fileData;
}
public byte[] FileToByteArray(string fileName)
{
byte[] fileData = null;

using (FileStream fs = File.OpenRead(fileName))
{
using (BinaryReader binaryReader = new BinaryReader(fs))
{
fileData = binaryReader.ReadBytes((int)fs.Length);
}
}
return fileData;
}
my byte reading code. TYIA , any and all help appreciated
26 replies
CC#
Created by Gibbo on 8/18/2023 in #help
❔ updating a DGV from another form on another thread
hi all, I'm wondering if you can help me with an issue I'm having updating a DGV. I'm getting a thread operation error as below: Cross-Thread operation not valid: Control 'dvgUSBDongles' accessed from a thread other than the thread it was created on Now I understand why I'm getting this and its because the form I'm trying to access it on was generated from a BackgroundWorker(so on a seperate thread) but im not too clued up on this currently and am unsure how to fix it. Everything ive done so far ive managed to do from from alot of googling. but threads/threading is just meh!!!! this is my code:
if (InvokeRequired == true)
{
Invoke(new Action(() => { mainformFunctions.RefreshData(); }));
Invoke(new Action(() => { this.Close(); }));
}
else
{
mainformFunctions.RefreshData();
this.Close();
}
if (InvokeRequired == true)
{
Invoke(new Action(() => { mainformFunctions.RefreshData(); }));
Invoke(new Action(() => { this.Close(); }));
}
else
{
mainformFunctions.RefreshData();
this.Close();
}
10 replies
CC#
Created by Gibbo on 7/22/2023 in #help
✅ Can you lock or freeze a thread while using another form in a new thread??
Part of my application requires i detect a USB device, and grab the DeviceID, I've got this and works fine, how ever im trying to get it to open a new form when it detects that the device is connected. again i got this working. the issue i got is i want it open a form and pass in a serial number from the USB. again i got this working but had to open the form by spawning a new thread. however dispite the form being open as Showdialog(), i can still access the main form. im assuming this is because they are on 2 separate threads. am i able to lock the previous thread while i have the new form open ??? and when it closes unlock it? this is my code for opening the form currently
private void DeviceInsertedEvent(object sender, EventArrivedEventArgs e)
{
// Update Interface to recognise USB inserted
lblUSBDetection.Text = "-- USB Inserted";

string serialNumber;

// Retrieve Serial Number from USB Device
ManagementBaseObject instance = (ManagementBaseObject)e.NewEvent["TargetInstance"];

foreach (var s in instance.Properties)
{
//Output all properties and values to debug console window for testing
//Debug.WriteLine(s.Name + " = " + s.Value);

if (s.Name == "PNPDeviceID")
{
string[] strings = s.Value.ToString().Split('\\');
serialNumber = strings[2];
Debug.WriteLine(serialNumber);

if (serialNumber != null)
{
//TODO if staement to show form if Serial matches serial stored in the data base, for now open form for all USB devices
new Thread(() => new USBPopup(serialNumber).ShowDialog()).Start();
}
break;
}
}
}
private void DeviceInsertedEvent(object sender, EventArrivedEventArgs e)
{
// Update Interface to recognise USB inserted
lblUSBDetection.Text = "-- USB Inserted";

string serialNumber;

// Retrieve Serial Number from USB Device
ManagementBaseObject instance = (ManagementBaseObject)e.NewEvent["TargetInstance"];

foreach (var s in instance.Properties)
{
//Output all properties and values to debug console window for testing
//Debug.WriteLine(s.Name + " = " + s.Value);

if (s.Name == "PNPDeviceID")
{
string[] strings = s.Value.ToString().Split('\\');
serialNumber = strings[2];
Debug.WriteLine(serialNumber);

if (serialNumber != null)
{
//TODO if staement to show form if Serial matches serial stored in the data base, for now open form for all USB devices
new Thread(() => new USBPopup(serialNumber).ShowDialog()).Start();
}
break;
}
}
}
40 replies
CC#
Created by Gibbo on 7/22/2023 in #help
duplicate outputs for usb inserted event
2 replies
CC#
Created by Gibbo on 10/27/2022 in #help
Text Manipulation
evening all, anyone free to help with a text manipulation issue? so im reading a log file that is in hex, ive used bit converter to push this out put to a RTB with no issues, my next task after a looking at how the hex is structured is to break the records into individual lines (records vary in length). here is a sample of the file entry and 1 record
00-00-00-00-00-00-00-00-24-00-00-00-24-00-00-00-00-00-00-00-E4-07-09-00-02-09-16-00-11-00-00-00-1A-00-77-01-48-A9-B9-13-6E-56-03-40-D7-56-03-40-48-8D-AF-1E-E7-07-00-00-E4-17-09-DF-02-09-16-75-11-90-00-5C-1A-91-77-01-61-28-F4-18
00-00-00-00-00-00-00-00-24-00-00-00-24-00-00-00-00-00-00-00-E4-07-09-00-02-09-16-00-11-00-00-00-1A-00-77-01-48-A9-B9-13-6E-56-03-40-D7-56-03-40-48-8D-AF-1E-E7-07-00-00-E4-17-09-DF-02-09-16-75-11-90-00-5C-1A-91-77-01-61-28-F4-18
there is some null data at the start that needs to be cleared out the 1st 47 characters once that is done i need to search for "00-00-E" count back 6 chars from the 1st "0" and insert a line break "\n", ideally i need to loop this until the end of the file, then display the output into a rtb to verify its looking correct and then save it to a new txt file, so i can decode it later 2 record output
00-00-00-00-E4-07-09-00-02-09-16-00-11-00-00-00-1A-00-77-01-48-A9-B9-13-6E-56-03-40-D7-56-03-40-48-8D-AF-1E-E7-07-00-00-E4-17-09-DF-02-09-16-75-11-90-00-5C-1A-91-77-01-61-28-F4-18
01-00-00-00-E4-A7-09-96-02-00-16-79-11-E1-00-E6-22-CD-B4-00-A9-18-3D-10-F9-96-7E-89-E9-93-B4-3C-70-B1-C2-9F-ED-BD-6F-7A-5A-45-00-0B-7E-16-04-DC-3F-DB-40-F0-87-FE-81-35-DB-C4-93-DA-86-E1-8D-31-93-71-51-88-4F-91-12-73-B5-FF-99-40-3F-66-AE-06-B9-DD-75-52-79-CE-37-B5-91-77-FA-39-02-61-EE-67-15
00-00-00-00-E4-07-09-00-02-09-16-00-11-00-00-00-1A-00-77-01-48-A9-B9-13-6E-56-03-40-D7-56-03-40-48-8D-AF-1E-E7-07-00-00-E4-17-09-DF-02-09-16-75-11-90-00-5C-1A-91-77-01-61-28-F4-18
01-00-00-00-E4-A7-09-96-02-00-16-79-11-E1-00-E6-22-CD-B4-00-A9-18-3D-10-F9-96-7E-89-E9-93-B4-3C-70-B1-C2-9F-ED-BD-6F-7A-5A-45-00-0B-7E-16-04-DC-3F-DB-40-F0-87-FE-81-35-DB-C4-93-DA-86-E1-8D-31-93-71-51-88-4F-91-12-73-B5-FF-99-40-3F-66-AE-06-B9-DD-75-52-79-CE-37-B5-91-77-FA-39-02-61-EE-67-15
i know the theory but lack ability at present any help appreciated
57 replies
CC#
Created by Gibbo on 9/23/2022 in #help
DGV Filtering
evening all ive got a DGV thats reading from a text file. ive setup a filter using a combo box and a text box. this works fine with the 1st column but not with any other this is my filter code private void tsTB_Search_TextChanged(object sender, EventArgs e) { string SearchColumn = tsCB_Search.Text; string SearchText = tsTB_Search.Text; string rowFilter = string.Format("[{0}] = '{1}'", SearchColumn, SearchText); (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = rowFilter; }
1 replies