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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
L

Leonardo Muzzi

@Leonardo Muzzi
About
Posts
24
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Encryption with tcpclient and tcplistner?
    L Leonardo Muzzi

    You can read it to an intermediate MemoryStream, still cryptografed, and after finishing reading you use the cryptoStream to decrypt the data.

    Regards, Leonardo Muzzi

    C# help sysadmin security question

  • High number of Handles
    L Leonardo Muzzi

    'Cause they are really different sockets. Diferent ip/port combination, different connections. The legacy application that answers to these sockets on the other side works like this. And I believe this is better , 'cause this application can receive many requests at the same time. Otherwise, it would block the connection until it gets the answer. I use the OnDataArrival event to receive the data, that is, assyncronous to the sending function.

    Regards, Leonardo Muzzi

    .NET (Core and Framework) csharp sysadmin tutorial question

  • High number of Handles
    L Leonardo Muzzi

    The application don't open and close sockets all the time: in fact, it just open and keep them opened. I must use different sockets to send and receive data. I have one thread per "send" socket. The "send" sockects are awalys opened and send data indefinitely, as long as it arrives in his own queue. There are 2 to 10 sockets like this being used at the same time, so 2 to 10 threads always active sending whatever arrives on the queue (separate queues). The "receive" sockets (one for each "send" socket) works using the OnDataArrival event. I suppose they use thread pool threads to fire the event. Anyway, I agree that what I need is a complete code revision to avoid memory leaks and some multithreading review too. The sockets doesn't seen to be the real problem. For example, there are too many "controls" over the queues, using some could-be-avoided multithread. I'll work on that direction. Does anyone know if the Enterprise Library can have something to do with this? It has been used to log some data in a sql server database. Thanks everyone for the support.

    Regards, Leonardo Muzzi

    .NET (Core and Framework) csharp sysadmin tutorial question

  • High number of Handles
    L Leonardo Muzzi

    Hi there. In my company, we have a windows service app that relies on multiple threads functionality to process many socket requests at a time, using the Socket events OnDataArrival to proccess the arriving data. Although the system is working properly, the server administrator is complaining that the app process is using a very high number of handles. That is, when you open the Windows Task Manager and check for the Handles column, the number is around 30000 handles for the process. I've checked some sources and a reasonable number of Handles for a single process is around 3000, and a 8000 is already a very high number. I'm way too over this. Do anyone has some good sources relating .net threads and events with the use of OS handles? I need some hints on how to low the number of hanldes for the process. I should probably re-do the app with good threading pratices (the implementation is very old), but I need a faster solution for the actual service.

    Regards, Leonardo Muzzi

    .NET (Core and Framework) csharp sysadmin tutorial question

  • How to run C# AND VB.NET applications together?
    L Leonardo Muzzi

    First you build an assembly with your C# library. Then send this assembly (DLL) to him, and he can reference this assembly in his own application. If he is using VS, just right click the project and "Add Reference". After adding the reference, his application will be able to see all your Namespaces and all public classes within it. If you are making a windows form app, you should separate the Executable from the Business library that you want to share. Let's say you have a method called "ListClients" in a "Clients" class and wants to share it. You should build a separate project, a Class Library project, called "ClientsAccess" for instance, and put this class in this new project. Then, you reference this project from your windows form app. This new Class Library project will generate a DLL, called "ClientsAccess.dll", that you can send to your colleague so he can reference the DLL just like you did and use the Clients class inside.

    Regards, Leonardo Muzzi

    C# csharp tutorial question

  • How to run C# AND VB.NET applications together?
    L Leonardo Muzzi

    Your colleague just need to reference your application (DLL). He will be able to use any public members of your library like a C# application would. After compiling an application, doesn't matter if it was written in C# or VB.NET, you use it the same way.

    Regards, Leonardo Muzzi

    C# csharp tutorial question

  • SoapException was unhandled by user code
    L Leonardo Muzzi

    Just guessing, but the problem might occur when some of your variables (username, pwd, persID, projectId, ....) have invalid chars, like xml schema chars. Seems your webservice is accessing other webservice, right? If you're using Visual Studio, you can just reference the other webservice (Right click on project -> Add Web Reference). VS will automatically create a new class encapsulating the webservice, so you just call for WebServiceClass.PS_CardsWithPersonReq method with the parameters. You might need WS Secutity to authenticate.

    Regards, Leonardo Muzzi

    ASP.NET csharp visual-studio xml asp-net dotnet

  • Lock(This)
    L Leonardo Muzzi

    The problem with Lock(this) and Lock(type) is that these objects are public, so an external code could lock on them. So if your class is named YourClass, I can make a code like this:

    YourClass obj = new YourClass();
    lock(obj){ ... }

    And that would probably deadlock your internal code. Same problem for a public type. Since it is commom to lock an object that you want to protect, it's not too dificult for a code like this to happen. The best approach is to create an object just for locking on it, instead of locking the class object. Make this locking object "static" and you get the same effect of locking a type.

    Regards, Leonardo Muzzi

    C# question help tutorial

  • Database Problem, Unknown Information in a Access DataBase by the MEMO type!
    L Leonardo Muzzi

    Well, it's definitely a String Base 64, 'cause I was able to build a byte array from it with this code:

        string strData = @"AORtHQTwD4AEAh4CSBEHSBFEgID8BwRIEEU1B0gRRP8BRQgFSBFE/wEEAwE4ABgiIDIJAPT/AgHpIjpFMwkA+J8CAVogOkU4CAD+AwAAAIB/AA8OEvkjjT/PI40/EQAAgD8eKLQBhvAdR4DpyGhwAAAAAAAAAAAAAAIAZ4yvRgAAnp8AACGhwAAAAAAKIgqE+ry+sL1Y4RhHXsCF8iV5DHKLKIJsTICFqxzDyy14ueEKIgmH5jDmMYFA51D5XSIqh+Ow47GwWG2Sug26";
        byte\[\] data = Convert.FromBase64String(strData);
    

    The problem is, I wasn't able to write it as an image in a .net page, using the Response.BinaryWrite method. So, maybe it's not a commom image binary data. You can test this byte array saving as a file and try some extensions.

    Regards, Leonardo Muzzi

    C# database com help question

  • Database Problem, Unknown Information in a Access DataBase by the MEMO type!
    L Leonardo Muzzi

    Seems to me that this is a binary field written in the String Base 64 format. You can try using Convert.FromBase64String to generate a binary stream, then you can try writing this stream as an image to the browser.

    Regards, Leonardo Muzzi

    C# database com help question

  • Merging Inputs and producting ID number [modified]
    L Leonardo Muzzi

    Hi there! I think the dynamic weights should be used if the scenario asks for them. If he needs to always make X1 more valuable than X2, than go with dynamic weights and increase W1 as long as he needs. If the scenario asks for different results based on the input sets, that you be nice! I think a good approach would be using dynamic weights, but vary them based on the results. That is, choose a formula (like the sum of factors, the vector modulus or any other), implement the solution, and make a test program that do as many tests as possible. Them compare the results generated with the desirable results, and vary the weights to get closer to the desirable. The test program could even vary the weights by himself. This would be close to a small neural network solution. The program learns how to proceed based on test data. The problem with this approach is that you need a large test data so the program can "learn" enough. About the memory usage, a very nice suggestion! I just think that maybe shrinking the more important factors (X1, X2,...) can compromise the solution, since the least significant bits of X1, for instance, could be more important than the whole X4. But again, that depends on the scenario. By the way, I forgot to mention that the vector modulus can be used with any quantity, not just 3, just adding more factors to the formula. Anyway, I think the author of the post has enough to work with! :)

    Regards, Leonardo Muzzi

    Algorithms help tutorial question

  • Access frames on different domain from Frameset
    L Leonardo Muzzi

    No. For security reasons, scripts cannot access other domains. You can try doing a similar code on the server side, that is, the .net (and not the browser script) would query the page and read the HTML for you. This can be achieved throught the System.Net.WebRequest class. After gathering all the HTML, you can just write it in a file or something.

    Regards, Leonardo Muzzi

    ASP.NET help algorithms question

  • Merging Inputs and producting ID number [modified]
    L Leonardo Muzzi

    Good. But maybe you could use smaller and more close numbers to multiply, or else a slight diferent X1 will never pass a threshold, and a very different X4 will always pass. I think you could do the same with different weights:

    long ID = (X1 * W1) + (X2 * W2) + (X3 * W3) + (X4 * W4);

    and vary the weights W1, W2, W3 and W4 and the threshold until you get a good result. As another solution, if your inputs are really 3 numbers, you could just treat them as mathematical three dimentional vectors and calculate the size of the vector, that is, the modulus of the vector. This would be:

    double Modulus = Math.Sqrt(X1*X1 + X2*X2 + X3*X3)

    You can also add weights in this formula, like X1*X1*W1 and so on. Then you can compare:

    if (If Math.Abs(Modulus1 - Modulus2) <= Threshold) ...

    Regards, Leonardo Muzzi

    Algorithms help tutorial question

  • Problem with firefox
    L Leonardo Muzzi

    You can use "buttons" that do not submit. Use HyperLink control. Use the ImageUrl property to set images, and NagivateUrl to set the page to navigate to. However, you won't be able to catch the click event in a postback, so you must pass any parameters in the NavigateUrl property.

    Regards, Leonardo Muzzi

    ASP.NET help question

  • Thread Sincronization Issue: Aborting thread with locked resources
    L Leonardo Muzzi

    Excelent text! This is what I needed to know: "All catch/finally blocks are honored, and never aborted mid-stream" So the first code would work. I'll check if I can change the writing operation to test a restart flag anyway! Thanks for the help ! (sorry for the self-reply)

    Regards, Leonardo Muzzi

    .NET (Core and Framework) help question announcement learning workspace

  • Thread Sincronization Issue: Aborting thread with locked resources
    L Leonardo Muzzi

    I'm thinking about implementing another thread that just sleeps for a while and checks for the flag, and abort the WritingThread if it finds the restart flag true. This new thread would hold the lock and therefore I can make sure it will release it. Still, I'm aborting threads and creating new ones. Is it good?

    Regards, Leonardo Muzzi

    .NET (Core and Framework) help question announcement learning workspace

  • Thread Sincronization Issue: Aborting thread with locked resources
    L Leonardo Muzzi

    Good ! :) I'll try implementing the "restart flag" inside the writing operation. But, let's say I can not interfere in the writing code (I don't know if I can, not my implementation), so I can't change the writing operation to test a flag eventually. Any other ideas? Thanks !

    Regards, Leonardo Muzzi

    .NET (Core and Framework) help question announcement learning workspace

  • Thread Sincronization Issue: Aborting thread with locked resources
    L Leonardo Muzzi

    Hi. I've a multithreaded service application with many threads accessing a comom resource. I have a typical Readers/Writers environment, where many threads may read at the same time but only one can write to the resource, exclusively. The thing is, whenever two threads (or more) asks for writing permission, I do not need to wait for the first thread to finish, I can just abort it (the first thread is no longer needed) and execute the second thread. Since writing is an expensive operation, it's desirable that I abort the first thread and execute the second. So, here's my doubt: if I abort a thread that holds a lock, will it release the lock? My simplified code looks like this:

    private static System.Threading.Thread WritingThread =
    System.Threading.Thread(MyClass.PerformWriting)

    private void TryWrite()
    {
    If (WritingThread.IsAlive)
    WritingThread.Abort();

    WritingThread.Start();

    }

    private void PerformWriting()
    {
    MyReaderWriterLockSlim.EnterWriteLock();

    try{
    //writing operation - takes a long time
    }
    finally{
    MyReaderWriterLockSlim.ExitWriteLock();
    }
    }

    So here's the deal. I have a commom fixed writing thread for everybody, so I can test if the thread is already running, and if is, I can just abort it and initiate it again. This get the effect of aborting the first writing and executing the second. Whenever a thread needs to write to the resouce, it just calls the TryWrite function. The original calling thread doesn't need to wait the end of the operation, so it returns and finishes. But, since "writing operation" takes a long time, it is more likely that the WritingThread will be aborted when it is writing, that is, when it holds the lock. Is that code ok, or it will deadlock when the thread gets aborted in the middle of the writing?

    Regards, Leonardo Muzzi

    .NET (Core and Framework) help question announcement learning workspace

  • Timer
    L Leonardo Muzzi

    Didn't know that. Maybe you have a command for refreshing the form?

    Regards, Leonardo Muzzi

    C# graphics tutorial

  • Timer
    L Leonardo Muzzi

    If you just want an interval, System.Threading.Thread.Sleep() should do the job.

    Regards, Leonardo Muzzi

    C# graphics 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