Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:23:35+00:00 2026-05-27T07:23:35+00:00

I am loading huge files to the memory but on this calculation my application

  • 0

I am loading huge files to the memory but on this calculation my application is freezes .

Any idea what is the issue with my code ?

public void Drop(DragEventArgs args)
{
  BackgroundWorker worker = new BackgroundWorker();
  string fileName = IsSingleTextFile(args);
  if (fileName == null) return;
  worker.DoWork += (o, ea) =>
  {
    try
    {
      StreamReader fileToLoad = new StreamReader(fileName);
      string filecontent = fileToLoad.ReadToEnd();
      fileToLoad.Close();
      // providing the information to the UI thread

      Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
        new Action(() => SfmLogFile = filecontent));
    }
    catch (Exception)
    {
      throw;
    }
  };

  worker.RunWorkerCompleted += (o, ea) =>
  {
    args.Handled = true;
    IsBusy = false;
  };

  // Mark the event as handled, so TextBox's native Drop handler is not called.

  IsBusy = true;
  worker.RunWorkerAsync();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:23:35+00:00Added an answer on May 27, 2026 at 7:23 am

    I’d transform your sample to something like this:

    public void Drop(DragEventArgs args)
    {
      string fileName = IsSingleTextFile(args);
      if (fileName == null) return;
      // It is better to create worker after check for file name.
      BackgroundWorker worker = new BackgroundWorker();
      worker.DoWork += (o, ea) =>
      {
        try
        {
          string filecontent = ReadAllText(fileName);    
          ea.Result = fileContent;
        }
        catch (Exception)
        {
          throw;
        }
      };
    
      worker.RunWorkerCompleted += (o, ea) =>
      {
        var fileContent = ea.Result as string;
        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
            new Action(() => SfmLogFile = filecontent));
    
        // if IsBusy propery is not on the UI thread, then you may leave it here
        // otherwise it should be set using the dispatcher too.
        IsBusy = false;
      };
    
      IsBusy = true;
      worker.RunWorkerAsync();
      // Mark the event as handled, so TextBox's native Drop handler is not called.    
      args.Handled = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading a few huge images on my flex/as3 app, but I can't manage
I'm getting this error in my application: # bin/ladvd -h bin/ladvd: error while loading
I have this huge problem with memory management. The problem : I've got a
Loading images into Flex (size < 100kb) causes IE7 memory increase by a megabyte
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
After loading a PHP template (using jQuery's load function), this simple script won't make
while loading getfptex(got it from CTAN) batch file ,when i'm extracting this batch file
Alright, I know questions like this have probably been asked dozens of times, but
I have a homepage that contains a huge amount of php code to populate
I want to update a huge text file in UITextView. But the device just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.