Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

SimpleData

@SimpleData
About
Posts
184
Topics
44
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • A problem while transferring data over the NetworkStream
    S SimpleData

    Wouldn't using the "lock" directive be enough?

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    Can you elaborate on "attempting to be clever by using threads for reading and writing"? Because it sounds like something I might have done. :)

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    I can't say that it is deterministic since if I pause the program at certain intervals, it can complete the transmission. If I don't pause the program at all, it stops after transferring 200-300KB. I am aware that what I am doing is just slowing down the transfer rate, but I am new to this are of programming and currently trying to develop this project to increase my experience. I will now add a timeout system to the server and request the rest of the data if nothing is incoming.

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    The connection is still intact, it doesn't drop. The only problem is that the server stops requesting chunks.

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    I am aware that the information with which I've provided you is less than sufficient, but it is really hard for me to isolate the code that works on the transfer, and there is a chance that isolating it from the rest of the application will leave you with no problem to solve. The problem may as well be stemming from the structure of the rest of the application. I will check if there is a problem with the file size tomorrow, but I don't think that is the problem. When I occasionally place a breakpoint and break the program, it manages to transfer a little bit more data (around 300KB more).

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    Thank you. Why haven't I thought of that. :) I will add that mechanism first thing tomorrow. By the way, even though this will probably solve my problem; there must still be a problem in my system since it is really unlikely for a package to be lost on a local TCP connection.

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    Yeah, sorry about that. While I am trying to transfer the data, it is stuck at some point. The server doesn't make any other requests and hence, the client doesn't send any more data. I have no idea why nothing new happens.

    C# csharp sysadmin help question

  • A problem while transferring data over the NetworkStream
    S SimpleData

    Hi, I am trying to send a big file over a TCP connection using NetworkStream and TCPClient. Both the client and the server is written in C#. There is no problem while transferring small files around the size of 300KB. My buffer size is 2KB and here is how the protocol works. -Server requests the file. -Client tells the server the size of the file, and then sends the first 2KB of it. -The server asks for another chunk of the file -like, send 2KB data, starting from 42649- -Client sends the chunk -Server asks for more, and client sends it... -When the end of file is reached, the client acknowledges the server that transfer is complete. Without looking at the code, since it is too long to be posted here, can you see any possible problems that may be causing this problem? I even tried sleeping the thread while receiving and processing the incoming chunks of data. Regards

    C# csharp sysadmin help question

  • File being used by another process? I don't think so!
    S SimpleData

    Thanks. I will make the necessary changes. By the way, in which way can this be causing my problem?

    C# help data-structures question discussion

  • File being used by another process? I don't think so!
    S SimpleData

    I am accessing the GUI elements within a thread that I've created and I didn't want to work with delegates because I didn't think it would constitute a problem in a minor project like this.

    C# help data-structures question discussion

  • File being used by another process? I don't think so!
    S SimpleData

    The code is only called once and it is in a thread. I haven't used the code Application.DoEvents() in any part of the application. I've used Control.CheckForIllegalCrossThreadCalls = false when the form is loaded. Do you think that it has something to do with this?

    C# help data-structures question discussion

  • File being used by another process? I don't think so!
    S SimpleData

    Hi, I am trying to code an application which reads some data from a NetworkStream, saves it into a buffer byte array and then appending it to a file. Here is the part I am writing the data from the byte array into the file:

    FileStream fs = new FileStream(last_save_location, FileMode.Append, FileAccess.Write);
    fs.Write(message, 8, bytesRead - 8);
    fs.Close();
    fs.Dispose();

    Everything seems to function fine. I can write the data from NetworkStream to the buffer byte array and then into the file for a while. However, after some time, I get the following error:

    The process cannot access the file 'C:\Users\Main\Desktop\test.bin' because it is being used by another process.

    I am quite sure that no other process is using the file and that I close the handle each and every time. What do you think the problem is? Regards, Can

    C# help data-structures question discussion

  • Speed difference between two functions with unknown reason
    S SimpleData

    Thank you all for your help. Now I got the idea and solved the problem. It would take me much longer to spot the cause by myself.

    C# docker performance question

  • Speed difference between two functions with unknown reason
    S SimpleData

    Now I got the idea. Thank you for your answers, this was a really hard thing to spot, for me. :)

    C# docker performance question

  • Speed difference between two functions with unknown reason
    S SimpleData

    Hi, I am not sure I understood your point exactly. if(pos % 204800 == 0) block is used in both cases but they still have speed differences.

    C# docker performance question

  • Speed difference between two functions with unknown reason
    S SimpleData

    I am using the Process Explorer from SysInternals and the first method creates an IO traffic with the magnitude of approx. 32MB, but the second one can't even exceed 1MB.

    C# docker performance question

  • Speed difference between two functions with unknown reason
    S SimpleData

    Hi, I have two methods, which are esentially doing similar jobs but have drastic speed differences. I don't know what is causing this speed difference. Here are the methods. The first one is like 100 times faster.

    private void SaveNativeBinary(string file, long origin, long length, string opt)
    {
    SetSSVisible(StatusStrip, pbSmallPerc, true);

            FileStream fs = null;
            FileStream writer = null;
    
            try { fs = new FileStream(file, FileMode.Open, FileAccess.Read); }
            catch { throw new Exception("ERR"); }
    
            try { writer = new FileStream(opt, FileMode.Create, FileAccess.ReadWrite); }
            catch { throw new Exception("ERR"); }
    
            fs.Seek(origin, SeekOrigin.Begin);
    
    
            for (long pos = 0; pos < length; pos++)
            {
                if (pos % 204800 == 0) // 200KB'da bir güncelle
                {
                    SetSSValue(StatusStrip, pbSmallPerc, Convert.ToInt32(PercentageCalc(pos, length)) );
                    SetSSText(StatusStrip, lblStatus, "Aktarılıyor: " + BtoKB(pos).ToString() + " / " + BtoKB(length).ToString() + " KB (%" + PercentageCalc(pos, length) + ")");
                }
                writer.WriteByte((byte)fs.ReadByte());
            }
    
            fs.Close(); fs.Dispose(); writer.Close(); writer.Dispose();
            SetSSVisible(StatusStrip, pbSmallPerc, false);
        }
    

    private void AppendBinToBin(string Container, string toAppend)
    {
    SetSSVisible(StatusStrip, pbSmallPerc, true);
    FileStream fsA, fsB = null;
    long tempLength = GetFileLength(toAppend);

            try { fsA = new FileStream(Container, FileMode.Open, FileAccess.ReadWrite); }
            catch { throw new Exception("ERR"); }
    
            try { fsB = new FileStream(toAppend, FileMode.Open, FileAccess.Read); }
            catch { throw new Exception("RRR"); }
    
            try
            {
                fsA.Seek(0, SeekOrigin.End);
                for (long pos = 0; pos < fsB.Length; pos++)
                {
                    if (pos % 204800 == 0) // 200KB'da bir güncelle
                    {
                        SetSSValue( StatusStrip, pbSmallPerc, Convert.ToInt32(PercentageCalc(pos, tempLength)) );
                        SetSSText( StatusStrip, lblStatus, "Aktarılıyor: " + BtoKB(pos).ToString() + " / " + BtoKB(tempLength).ToString() + " KB (%" + PercentageCalc(pos, tempLength) + ")" );
    
    C# docker performance question

  • How to search for a specific string in a file?
    S SimpleData

    Thanks for the advices. I will change the code accordingly. This algorithm covers my needs. It works, it is fast and it doesn't consume much RAM. :)

    C# help tutorial question data-structures json

  • How to search for a specific string in a file?
    S SimpleData

    I am open to suggestions.

    C# help tutorial question data-structures json

  • How to search for a specific string in a file?
    S SimpleData

    Yes, but I think that is not a problem for me. I am looking for a string in the file, no matter where it is. I think code can express everything, in a better way. Here is my code:

    private long DigBinary(string file, string strToDig)
    {
    FileStream fs = null;

            char\[\] chAim = strToDig.ToCharArray();
            char chTemp = '0';
            long latestHitBeginningLocation = 0;
            int locationInArray = 0;
    
            try { fs = new FileStream(file, FileMode.Open, FileAccess.Read); }
            catch { throw new Exception("An error occured while creating the stream."); }
    
            try
            {
                while (locationInArray < chAim.Length)
                {
                    chTemp = (char)fs.ReadByte();
    
                    if( chTemp != chAim\[locationInArray\] )
                        locationInArray = 0;
    
                    if (chTemp == chAim\[locationInArray\])
                    {
                        if (locationInArray == 0)
                            latestHitBeginningLocation = fs.Position - 1;
    
                        if (locationInArray == chAim.Length)
                            break;
    
                        locationInArray++;
                    }
                    else
                    {
                        locationInArray = 0;
                        latestHitBeginningLocation = 0;
                    }
                }
            }
            catch { throw new Exception("An error occured while reading the file."); }
            finally { if (fs != null) { fs.Close(); fs.Dispose(); } }
    
            return latestHitBeginningLocation;
        }
    

    And yes, I know that my try-catch is useless. :D

    C# help tutorial question data-structures json
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups