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
T

Trapper Hell

@Trapper Hell
About
Posts
27
Topics
14
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • globalizatin
    T Trapper Hell

    This seems to be your first post and you didn't even bother write 'Globalization' down properly or ask the questions in a more 'inquisitive' manner, rahter than just copying and pasting :p However, you are lucky, I just solved your first question: Click Here...

    C# csharp java

  • Hardware Acceleration on a PictureBox / Non-Apparent Image in Screenshot
    T Trapper Hell

    What I want is NOT to capture.. I want to make the system so that the image will not be captured when a screenshot is taken... However implementing a lock upon the PrintScreen key is not the ideal way... What I had in mind, is implementing it similar to how it works when a video is played on a PC with Hardware Acceleration on - the image is 'translucent' or something, so that it does not show up on the screenshot...

    C# csharp hardware question

  • Hardware Acceleration on a PictureBox / Non-Apparent Image in Screenshot
    T Trapper Hell

    I have this application that in very brief, shows up an image from time to time... Now, you know that if you press PrintScreen whilst a video is running, the image derived does not show the screen (if Hardware Acceleration is turned on). I was wondering if I could achieve this in C# (without going into great lengths) - to make the image non-apparent on PrintScreen... Or if I should use a completely different method? I had in mind of tracking the Clipboard but that would take me to great lengths and can be easily circumvented.

    C# csharp hardware question

  • ObjectDisposedException within a while loop?
    T Trapper Hell

    I'm posting just to let you know of a few 'updates'. I haven't changed the code yet, but I will soon enough, and I'll inform you then. At the moment: 1. 'shootName' is used but not in that code extract. It's in the same method, but it's set in a if...else situation, which is irrelevant :) 2. I'm not sure if this is my misconception or anything, but I had rather thought that if an object is set to null, this makes GC more likely/quickly to occur on that object, to release the resources occupied by it? If this is my mistake, than I'm glad to know :) 3. I'll check TempSaveStream() again to ensure that it's not causing the problem. Furthermore, I WILL ;) check the exception handling, due to the embarrassing exception handling I've implemented in the other conversation we've had ;P Besides, I will check certain properties in the ZipFile class, since, for instance, there is a particular property that once the child's finished, it also closes the parent zip. So it may be something along those lines :-O Thanks for taking the time :) I'll keep you informed

    C# data-structures tutorial question

  • NetworkStream problem...
    T Trapper Hell

    Guess what. It worked! :-D There are still a couple more things to work upon, but that was really starting to bug me! The way I saw it, I thought it had to do with timeouts or something, since the data was partially read, now I realize it's all in that class' miserable coding lol. :-O Thank you so much Luc! You're a life-saver :laugh: :thumbsup::thumbsup: P.S. I wanted to add that post as a Good Answer but it's only appearing on the first post you made... Sorry about that haha.

    C# help question

  • NetworkStream problem...
    T Trapper Hell

    This is just to inform you that I have just amended most code as you kindly suggested. With regards to exception handling, I must say that I have been a bit careless in implementing them, thus that is why they lack so much - sorry about that. Now I have now implemented two methods: void Send(object obj) - which serializes the object immediately into a NetworkStream. object Receive() - which deserializes from the NetworkStream into an object. Obviously enough this should be much better both in terms of performance and simplicity of code. I'm not sure that this would solve the problem of not being able to receive all the data (I don't expect it too anyway), and I'll keep you informed. I would like to thank you once again, however, if you get an idea on how to ensure that all data is read, I kindly ask you to reply with that :) Thanks so much!

    C# help question

  • NetworkStream problem...
    T Trapper Hell

    As requested, I will attempt to answer all the questions provided so that I may be provided with an answer which will solve this problem...

    Luc Pattyn wrote:

    - information on how both PCs are connected

    Physically the PCs are on a LAN, thus the network speed should be of no problem. There are multiple connections established in C#, all in TCP/IP. There are about three open ports on each side, each with a separate network stream for separate purposes. However, the exception only occurs in one of these.

    Luc Pattyn wrote:

    - information on the data written each time: is it text? binary data? how much? what does it represent?

    The data transferred in this particular NetworkStream is binary data representing a serialized Bitmap instance. Whilst the length of the serialized Bitmap instance varies every time, it is around ~710500 bytes long...

    Luc Pattyn wrote:

    - the entire code of the method that writes the data, and its context (which thread, how is it triggered, etc)

    The method called is Send(object) which looks as follows:

    public bool Send(object oSend)
    {
    try
    {
    SendString(Serialize(oSend).Length.ToString());
    return SendBytes(Serialize(oSend));
    }
    catch
    {
    return false;
    }
    }

    Serialize is as follows:

    public byte[] Serialize(object oSerialize)
    {
    if (oSerialize != null)
    {
    lock (serializeLock)
    {
    msMem = new MemoryStream();
    bf = new BinaryFormatter();

                    try
                    {
                        bf.Serialize(msMem, oSerialize);
                        msMem.Flush();
                        msMem.Position = 0;
    
                        oSerialize = null;
                        bf = null;
                        return msMem.ToArray();
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
            else
                return null;
        }
    

    SendString:

    public bool SendString(string strSend)
    {
    try
    {
    SendBytes(new System.Text.ASCIIEncoding

    C# help question

  • ObjectDisposedException within a while loop?
    T Trapper Hell

    First of all I would like to thank you for taking the time to reply :) You really seem like you want to help ;) So, I totally agree with you that by simplifying the code I might also be hiding the problem. The program functions as follows. At every specified interval, the application extracts an image from a ZIP file according to "liked shoots" since this is based on a group of photographers each having their own shoots submitting, and so on... The code in demand is a follows:

    private byte[] GetShootImage(ZipFile originalZipFile, string pass, string shootName)
    {
    while (fm.LikedShoots.Count > 0) // fm is a class containing the "liked shoots" - by names
    {
    ZipFile shootZipFile = originalZipFile; // <-- ERROR OCCURS HERE!!
    ZipEntry zipEntry = shootZipFile.GetEntry(fm.LikedShoots[0]);

    if (zipEntry != null)
    {
        TempSaveStream(shootZipFile.GetInputStream(zipEntry), zipEntry.Size, true); // Saves the an entry of the ZipFile (which is yet another ZipFile to a temporary file (C:\\WINDOWS\\Temp)
    
        zipEntry = null;
    
        shootZipFile.Close();
        shootZipFile = null;
    
        shootZipFile = new ZipFile("C:\\\\WINDOWS\\\\Temp\\\\TpTmp\\\\temp.tmp");
        shootZipFile.Password = pass;
    
        // For each photo in the Shoot...
        foreach (ZipEntry entry in shootZipFile)
        {
            // If Image is not generated
            if (!fm.ImageGenerated(fm.LikedShoots\[0\] + "\\\\" + entry.Name))
            {
                // List the Image in the GeneratedPhotos list
                fm.GeneratedPhotos.Add(fm.LikedShoots\[0\] + "\\\\" + entry.Name);
    
                // Get the Image in a byte\[\] (instead of saving it)
                buffer = TempSaveStream(shootZipFile.GetInputStream(entry), entry.Size, false);
    
                shootZipFile.Close();
                shootZipFile = null;
    
                return buffer;
            }
        }
    }
    
    // Add the Shoot to the ExhaustedShoot list
    fm.ExhaustedShoots.Add(fm.LikedShoots\[0\]);
    // Remove the Shoot from the LikedShoots list
    fm.LikedShoots.RemoveAt(0);
    

    }
    }

    On the 2nd loop, the marked line of code throws an ObjectDisposedException within the originalZipFile object. However, as you can see, originalZipFile is not set to null or anything. Can the GC have collected it or what? In the mean, I would like to thank you so much for taking the time to reply.

    C# data-structures tutorial question

  • ObjectDisposedException within a while loop?
    T Trapper Hell

    I have this method that accepts a ZipFile as a parameter and does some work etc, but after looping within a while loop, the parameter (ZipFile) is disposed... I will show a quick example instead of the original code because it would be unnecessarily complex.

    private byte[] GetImage(ZipFile originalZipFile, string pass)
    {
    while(true) // Here is a condition that loops for some time, according to a specified number
    {
    ZipFile zipFile = originalZipFile // <- Exception occurs here, after the 2nd loop (originalZipFile is somehow disposed)
    foreach(ZipEntry zEntry in zipFile)
    {
    if(true) // If the condition is met, the object is returned
    return new byte[];
    }
    }
    }

    I have attempted to keep the example simple enough.. So, zipFile is closed and set to null within the while loop, even before the return (else an exception occurs, since the ZipFile is using a FileStream which is later needed). However, originalZipFile is for some reason being disposed without any calling directly accessing it :mad: (that is why originalZipFile is copied into zipFile) What can I do in order to keep originalZipFile from being disposed? Or what am I doing wrong? Thanks! (As far as I am concerned, ZipFile is a class not a struct, so there shouldn't be any problems, with multiple references to the same 'object' on the stack).

    C# data-structures tutorial question

  • Win Form - resize form problem
    T Trapper Hell

    As the others have already answered. The controls aren't set to grow automatically... If that helps solving the problem, you can set the border to Fixed (so that it is not resized), however that doesn't solve the problem. To actually solve the problem you can either handle the Resize event and grow the controls accordingly, but what would seem better (and easier) would be to click the controls in Designer mode and setting their Anchor to the most according manner. I have had no problems with this method so far. With regards to the last part of your question, I believe that you can get to know the previous size by checking on the ResizeBegin event, and comparing with the ResizeEnd or Resize event. There might be easier solutions, it's just one that came to my mind at the moment. Regards, Trapper

    C# csharp help question

  • NetworkStream problem...
    T Trapper Hell

    I have already asked this question before (but was left unanswered), so I am attempting again, this time refining this question, and hoping that somebody that reads this, would be able to answer. The problem is this... I have this application that sends data to another application on very short intervals (~250ms) between one write and another. This all works great on most PCs but on some others it doesn't work well at all. Reason being, that on the receiving-end, before being able to read all the bytes, the later parts of the data would become all 0s. I don't know if this is a timeout or what? The current code is very simple but works fine (on most PCs): nsStream.Write(buffer, 0, buffer.Length); // Buffer being a byte[] containing the data nsStream.Read(buffer, 0, buffer.Length); // Buffer being a byte[] with a pre-determined size I have attempted to encapsulate the NetworkStream within a BufferedStream but it only made the situation worse - it doesn't work on the PCs that it used to... Any help is greatly appreciated!

    C# help question

  • NetworkStream, possibly Read timeout?
    T Trapper Hell

    I have these two applications, one of which sends a screenshot image to the other. This works smoothly on most PCs, however some (older) PCs start receiving a lot of zeros after reading some of the data. How can I ensure that all the data being sent, is read? I don't know if this is a timeout issue, or what? (I have found some solutions, such as WriteByte / ReadByte, but I need it to perform quite fast too, if possible) The methods are as follows: Sending:

    if (nsStream.CanWrite)
    nsStream.Write(bUp, 0, bUp.Length);

    nsStream.Flush();

    int x = 0;

    while (nsStream.DataAvailable && x < dataReadWait)
    {
    x++;
    // Wait for data to be read
    }

    return true;

    Receiving:

    if (nsStream.CanRead)
    nsStream.Read(bDown, 0, bDown.Length);

    nsStream.Flush();
    return bDown;

    At this point, it is worth saying that the Sender prior to sending the actual image, sends the length of the image (which is assigned to bDown), that is why data is read until the length of bDown... Any help is so greatly appreciated!

    C# help question

  • BinaryFormatter.Deserialization SerializationException
    T Trapper Hell

    I have been working on this issue for a few days now and I am growing tired and desperate :sigh: I have made this application which sends a screenshot (Image type) to another PC. All works well on most PCs except some very few of them. Those that do not work complain of a Binary stream '0' does not contain a valid BinaryHeader. The code is exactly the same on the working / non-working PCs. I have also attempted to run the program locally on the PCs not working, and the exact problem occurs. The Algorithm is as follows: - Screenshot is taken (returned as Image) - Size of the Image is sent (to prepare a byte[] for the receiving end) - Image is converted into a MemoryStream from BinaryFormatter.Serialize - MemoryStream.ToArray() gets byte[] which is written on a NetworkStream - Receiving end receives the length of the object and prepares a byte[] with that length - Receiving end reads the data on a byte[] - Byte[] is Deserialized to object <- Exception occurs X| I have checked the first 50 bytes being sent and received and they are exactly identical!! :doh: It is true that the first byte is a 0 but this works with no problems at all on other systems Why is this happening? How can I avoid this? Maybe using UnsafeDeserialize or something completely different?! :confused: Any help is sooo greatly appreciated!!

    C# help question algorithms

  • TcpListener.AcceptTcpClient OR TimeOut
    T Trapper Hell

    It seems that I'm stuck on something small but I've been working on it for quite some time and I'm exhausted... I have a method that returns a bool whether a TcpConnection was successful or not... The method attempts TcpListener.AcceptTcpClient however I want it to return false if no client has been connected within a specified time (e.g. 2000 milliseconds)... How can I achieve this? I attempted the .BeginAcceptTcpClient and .EndAcceptTcpClient but these still block OR if I use the Thread.Sleep() I block the method from accepting any connecting client.. I need the result to be returned if a TcpClient is accepted or the operation 'timed-out' - whichever comes first. Please help!

    C# help question

  • Most efficient way of taking a screenshot? [modified]
    T Trapper Hell

    I must say that that was really helpful...

    C# graphics question

  • Most efficient way of taking a screenshot? [modified]
    T Trapper Hell

    The Subject says it all... At the moment I am using the following method:

    Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

    Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);

    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

    However, since I need to be taking screenshots at around every 250ms, I need to find the most efficient way possible (if any)... Thanks! Note: I have found that taking partial parts of the screen is much more efficient, but at the moment I need all the screen taken...

    modified on Monday, July 20, 2009 3:22 AM

    C# graphics question

  • 'Screen Capture' Performance Improvement Suggestions...
    T Trapper Hell

    Thanks about that... I'll check Part 1 you mentioned. However, with regards to Part 2, that would only improve the Server or the network bandwidth, but not the processing, since a lot of time is spent comparing... However, thanks for taking the time to answer... Please provide me with the possibilities of reducing the lines in the ScreenCapture method. Thanks!

    C# graphics sysadmin performance css asp-net

  • 'Screen Capture' Performance Improvement Suggestions...
    T Trapper Hell

    Whilst I would like to thank you for taking the time to read and attempt to resolve the problem, that actually made the situation worse. Since on average, CPU usage increased by another 2%.

    C# graphics sysadmin performance css asp-net

  • 'Screen Capture' Performance Improvement Suggestions...
    T Trapper Hell

    The main question I have here is how to improve CPU usage... Memory Usage is not an issue :) The Client program connects to the server and sends screen shots (at a rate of 250ms) to the server. This all works well, but I need to use less CPU... The server side program is of no concern either ;) For brevity purposes, I will simply list what's used. First of all, a TcpClient and a NetworkStream are used. BinaryFormatter serialization is also used to de/serialize objects into byte arrays. The conversion of an object to a string is not quite a choice, since I intend to transfer more objects later on (without having to change much code). A timer with interval of 250ms triggers DoWork method of a BackgroundWorker to take and send a screen shot. The method used to take the screen shot is:

    private Image TakeShot()
    {
    Bitmap bmpScreenShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
    Graphics grcShotGraphic = Graphics.FromImage(bmpScreenShot);
    grcShotGraphic.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            grcShotGraphic.Dispose();
            return (Image)bmpScreenShot;
        }
    

    I just need to know what's causing such CPU usage and how to improve it. E.g. using Threads instead of BackgroundWorker or a more efficient method to take the screen shot. As I have said, Memory Usage and Network load is of no concern. Furthermore, I know that increasing the interval would result in better performance, but I am looking for something other than that. Current CPU usage ranges between 20-40% on an Intel Core 2 Duo E7300 :sigh:

    C# graphics sysadmin performance css asp-net

  • Sending Multiple Network Streams Simultaneously...
    T Trapper Hell

    I am working on a RAT (Remote Administration Tool)... Below is an explanation and the question... If you'd like you can skip the rest and read the question :) [Program Explanation] A program working on the Admin-side sends a command to the Client-side program (through TCP/IP), and after interpreting the instruction, it does the requested action. For example, if the Admin-side sends "list drives", the Client-side program interprets the command and sends a string[] back to the Admin as a byte[]... The admin-side would convert the byte[] to a string[] That's no big deal... [End of Program Explanation] [Question] The question is... Can I send multiple Network Streams at one time, and each are separately recognized by the receiving-end? This is important if more than one task are performed at one time - such as getting a file and keyboard logs... (Since the conversion at the receiving-end needs to be made for the relevant response... Last I tried, I sent two different Network Streams exactly after each other and the receiving end had thought that it was the same stream!! - It resulted in total chaos ;) [End of Question] [Program Coding] To send a command, there are two important methods

    public byte[] Serialize(object oSerialize)
    {
    ms = new MemoryStream();
    bf = new BinaryFormatter();
    bf.Serialize(ms, oSerialize);
    return ms.ToArray();
    }

    public byte[] Serialize(object oSerialize)
    {
    ms = new MemoryStream();
    bf = new BinaryFormatter();
    bf.Serialize(ms, oSerialize);
    return ms.ToArray();
    }

    On the receiving end, a similar system is used, being Receive and DeSerialize... [End of Program Coding]

    C# question sysadmin json tutorial
  • Login

  • Don't have an account? Register

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