views:

21

answers:

1

hi I am working a client/server application in C#. My server Capture current Mouse Cursors and send these to client so that Cursor of the cleint also chage accordingly.I can detect windows Cursors and serialize them over binaryformatter. it works fine but but problem is there are many cursors that can not be detected like mspaint cursors so i have to take its handler and create the cursor and its x nad y hotspots and add them in an arraylist and serialize it over network but after 10 to 15 minute it thorws exception "Error HRESULT E_FAIL has been returned from a call to a COM Compeonet" and cleint throws the exception of "Exception thrown by target of invocation" Can anybody guid me what going wrong ort some better way to do like this Some code is here

IntPtr curInfo = GetCurrentCursor();
                Cursor cur;
                Icon ic;
                byte cursor = 0;

                if (curInfo != null && curInfo.ToInt32() != 0)
                {
                    cur = CheckForCusrors(curInfo);
                    try
                    {
                        if (!isLinuxClient)
                        {

                            if (cur == null)
                            {

                                PlatformInvokeUSER32.GetIconInfo(curInfo, out temp);
                                ic = Icon.FromHandle(curInfo);
                                //bitmap = ic.ToBitmap();
                                ArrayList ar = new ArrayList();
                                ar.Add(ic);
                                ar.Add(temp.xHotspot);
                                ar.Add(temp.yHotspot);
                                b.Serialize(stm, ar);
                            }
                            else
                            {
                                ArrayList ar = new ArrayList();
                                ar.Add(cur);
                                b.Serialize(stm, ar);
                             }
                        }
public Cursor CheckForCusrors(IntPtr hCur)
        {
            if (hCur == Cursors.AppStarting.Handle)
                return Cursors.AppStarting;
            else if (hCur == Cursors.Arrow.Handle)
                return Cursors.Arrow;
                          .
                          .
                          .
                else if (hCur == Cursors.PanWest.Handle)
                return Cursors.PanWest;

            return null;
        }

`

A: 

Try to dispose all of your created handles, for example:

                        using(ic = Icon.FromHandle(curInfo)) {
                            //bitmap = ic.ToBitmap();
                            ArrayList ar = new ArrayList();
                            ar.Add(ic);
                            ar.Add(temp.xHotspot);
                            ar.Add(temp.yHotspot);
                            b.Serialize(stm, ar);
                        }
Yossarian