473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

c# report progress to backgroundworker from another class

i'm working on uploading file to filehost. i'm using listgridview to show filename and its size and also progress bar for each individual file like below.




I'm performing upload in class manner.

From main class i'm calling openload class to provide File location. In openload upload class i check authentication and gets upload adress and send that upload adress to another class named Upload which performs multipart/form-data upload.

Everything is working fine without using progress bar. But i want to implement progress bar to run sucessfully.

I'm using backgroundworker in my main class to call openload function and provide file location.

Expand|Select|Wrap|Line Numbers
  1. private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
  2.             {
  3.                 if (!string.IsNullOrEmpty(File))
  4.                 {
  5.                     var Link = new FileHost.Openload();
  6.                     OutputBox.Text = Link.Upload(File);
  7.                 }
  8.             }
Then it goes to openload class where it check authentication and provide upload url to upload class.

Expand|Select|Wrap|Line Numbers
  1. Upload Upload = new FileHost.Upload();
  2.                     Thread Uploading = new Thread(() =>
  3.                     {
  4.                         UploadResult = Upload.UploadFilesToRemoteUrl(UploadURL, FileName, null);                        
  5.                     });
  6.                     Uploading.Start();
in my Upload class it performs uploading in stream format.


Expand|Select|Wrap|Line Numbers
  1. using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
  2.                 {
  3.                     var buffer = new byte[1024];
  4.                     int totalReadBytesCount = 0;
  5.                     var bytesRead = 0;
  6.                     while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
  7.                     {
  8.                         memStream.Write(buffer, 0, bytesRead);
  9.                         totalReadBytesCount += bytesRead;
  10.                         var progress = totalReadBytesCount * 100.0 / fileStream.Length;
  11.                     }
  12.                 }
It also provides progress of upload. but i want to provide value of progress to backgroundworker reportprogress.
but i can't call main class backgroundworker to working class i.e. upload class.

is there any method or delegate to call backgroundworker of main class in another class.
Oct 7 '18 #1
0 2299

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Hal Vaughan | last post by:
I'm creating a sequence of JPanels that will each, in turn, be added to (then removed from) a window (kind of like a wizard). I want these panels to not only extend the JPanel class, but to...
5
by: Stewart Midwinter | last post by:
I've got an app that creates an object in its main class (it also creates a GUI). My problem is that I need to pass this object, a list, to a dialog that is implemented as a second class. I want...
11
by: Bob Rock | last post by:
Hello, I'd like to be able to allow instanciation of a class (class Class_A) only from another class method (class Class_B). And I'd like to write the necessary code to enforce this behavior...
6
by: SearedIce | last post by:
Consider the following simplified hypothetical code: #include <iostream.h> class rabbit { public: rabbit() {x = 3; y = 3; /*code here to set field to 1*/} void runtocage(); int x;
5
by: M O J O | last post by:
Hi, I want to expose a enum from another class, is that possible and how? Here's an example Public Class ClassMaster Public Enum Colors
4
by: Art | last post by:
Hi, I have a main form for my project. It uses a routine in another class to do work on a file -- line by line. I'd like to have a text box on my form display the lines, say every 5,000 -- so...
4
by: Steve Goldman | last post by:
Even asking this question probably demonstrates that I have a fundamental misunderstanding of how values and references work in C#, but here goes: I'd like to assign a reference to an arbitrary...
3
by: drummond.ian | last post by:
Hello Everyone, This problem's been causing me a lot of trouble and I'm hoping somebody can help me out!! I have a dialog-based MFC application in visual studio 2003. I want to call a...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
2
by: DragonLord | last post by:
How do you update a progress bar on your main form from another class int he project (C#)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.