Click here to Skip to main content
15,918,267 members
Home / Discussions / C#
   

C#

 
AnswerRe: Can not open 'User Management' in the request database. Login failed. Pin
Mycroft Holmes23-May-10 23:05
professionalMycroft Holmes23-May-10 23:05 
QuestionSystem.ObjectDisposedException: Cannot access a disposed object. Pin
Jacob Dixon23-May-10 18:17
Jacob Dixon23-May-10 18:17 
AnswerRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn23-May-10 19:02
sitebuilderLuc Pattyn23-May-10 19:02 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Jacob Dixon24-May-10 2:44
Jacob Dixon24-May-10 2:44 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn24-May-10 4:25
sitebuilderLuc Pattyn24-May-10 4:25 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Jacob Dixon24-May-10 5:01
Jacob Dixon24-May-10 5:01 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn24-May-10 5:06
sitebuilderLuc Pattyn24-May-10 5:06 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. [modified] Pin
Jacob Dixon24-May-10 5:26
Jacob Dixon24-May-10 5:26 
Here is my updated version. I set the thread to IsBackground = true and also on frmViewAsset closing it calls lp.Stop();

public void Load()
{
    SqlConnection conn = new SqlConnection(AssetConfig.ConnectionString);
    SqlCommand cmd = new SqlCommand("SELECT Picture FROM Inventory_Pictures WHERE PictureID=@Tag", conn);
    cmd.Parameters.AddWithValue("@Tag", Tag);

    try
    {
        conn.Open();

        IDataReader r = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
        if (r != null)
        {
            bool exist = r.Read();

            if (exist)
            {
                long size = r.GetBytes(0, 0, null, 0, 0);
                byte[] buffer = new byte[size];
                int bufferSize = 65536;
                long bytesRead = 0;
                decimal prevPercent = 0;

                while ((bytesRead < size) && ((size - bytesRead) > bufferSize))
                {
                    if (stop)
                        break;

                    long newAmount = r.GetBytes(0, (Int32)bytesRead, buffer, (Int32)bytesRead, bufferSize);
                    bytesRead += newAmount;

                    if (newAmount == 0)
                        break;

                    decimal FileSize = (size / 1024) / 1024;
                    decimal CurrentSize = (bytesRead / 1024) / 1024;

                    if (ProgressChanged != null && !stop)
                    {
                        decimal currentPercent = (CurrentSize / FileSize) * 100;
                        if (currentPercent != prevPercent)
                            ProgressChanged((int)CurrentSize, (int)FileSize, Math.Round(CurrentSize, 2).ToString(), Math.Round(FileSize, 2).ToString());

                        prevPercent = currentPercent;
                    }
                }

                if (!stop)
                {
                    MemoryStream ms = new MemoryStream(buffer);
                    if (Finished != null)
                        Finished(Image.FromStream(ms));

                    ms.Close();
                }
            }
            r.Close();
        }
    }
    catch (Exception ex)
    {
        Error.WriteError(ErrorType.SQL, "LoadPicture", ex.ToString());
    }
    finally
    {
        if (conn != null)
        {
            conn.Close();
            conn.Dispose();
        }

        if (cmd != null)
            cmd.Dispose();
    }
}



Problem is ProgressChanged is apparently being called after frmViewAsset disposes??

[5/24/2010 10:39:13 AM LoadPicture]: System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at System.Windows.Forms.Control.Invoke(Delegate method)
   at AssetMgmt.frmViewAsset.p_Finished(Image img) in C:\Applications\Windows Applications\AssetMgmt\AssetMgmt\frmViewAsset.cs:line 379
   at AssetMgmt.LoadPicture.Load() in C:\Applications\Windows Applications\AssetMgmt\AssetMgmt\Operations\LoadPicture.cs:line 81

It fails on the Finished.. I think only because I can't close the window quick enough during the Progress. Funny thing is I saw the image appear in the picturebox before it finally closed and it still showed this


modified on Monday, May 24, 2010 11:39 AM

GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn24-May-10 6:23
sitebuilderLuc Pattyn24-May-10 6:23 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Jacob Dixon24-May-10 6:41
Jacob Dixon24-May-10 6:41 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn24-May-10 6:54
sitebuilderLuc Pattyn24-May-10 6:54 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Jacob Dixon24-May-10 7:13
Jacob Dixon24-May-10 7:13 
GeneralRe: System.ObjectDisposedException: Cannot access a disposed object. Pin
Luc Pattyn24-May-10 7:27
sitebuilderLuc Pattyn24-May-10 7:27 
Questiontype object Pin
tek 200923-May-10 10:32
tek 200923-May-10 10:32 
AnswerRe: type object Pin
Pete O'Hanlon23-May-10 10:46
mvePete O'Hanlon23-May-10 10:46 
AnswerRe: type object Pin
tek 200923-May-10 12:28
tek 200923-May-10 12:28 
QuestionOutput type of Class Library cannot be started directly Pin
tan_chin23-May-10 9:33
tan_chin23-May-10 9:33 
AnswerRe: Output type of Class Library cannot be started directly Pin
#realJSOP23-May-10 9:58
professional#realJSOP23-May-10 9:58 
GeneralRe: Output type of Class Library cannot be started directly Pin
tan_chin23-May-10 10:28
tan_chin23-May-10 10:28 
GeneralRe: Output type of Class Library cannot be started directly Pin
Dave Kreskowiak23-May-10 18:26
mveDave Kreskowiak23-May-10 18:26 
AnswerRe: Output type of Class Library cannot be started directly Pin
Pete O'Hanlon23-May-10 10:00
mvePete O'Hanlon23-May-10 10:00 
GeneralRe: Output type of Class Library cannot be started directly Pin
tan_chin23-May-10 10:29
tan_chin23-May-10 10:29 
QuestionExcel number of rows Pin
gmhanna23-May-10 7:37
gmhanna23-May-10 7:37 
AnswerRe: Excel number of rows Pin
Abhinav S23-May-10 7:42
Abhinav S23-May-10 7:42 
QuestionArraylist Goes Null after Passing information back to Main Page from Window. Pin
PDTUM23-May-10 7:23
PDTUM23-May-10 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.