Update UpdatePanel without a control? - c#

I currently have a process that does the following:
Read a remote file and parse complex data;
Dynamically create a bitmap image based on the data;
Display the bitmap in an Image control in an Updatepanel.
Wait 15 seconds, then repeat the whole process.
I have set myScriptManager.RegisterAsyncPostBackControl(myTimer), and run the whole process (all three steps in sequence) on myTimer_Tick, and I have set the timer's Interval to 15 seconds, which is ideal for my purposes. However, step 1 above could take as long as a minute (in very rare cases), and I'm not entirely sure what will happen in that case? What will happen if the myTimer_Tick fires after 15 seconds and start it all again, when the previous run hasn't completed?
Ideally I'd like to update the UpdatePanel programmatically when the last line of code for Steps 1 to 3 have been finished, and then use Thread.Sleep to pause for 14 seconds before repeating, as it usually takes about 1 second to do steps1-3. However, I have no idea how to make the UpdatePanel update without linking it to a control. Why can't I just say myUpdatePanel.Upate() at the end of any chunk of code?

Related

Updating a foreground service notification using a Timer that works even when the device is in Doze/Sleep mode

I have a Timer (System.Timers) which is wrapped into an object that exposes two events. One that fires every second, and one that fires every 7 minutes. The event that fires every second, is updating a foreground service notification with a countdown. The event that fires every 7 minutes is updating an int value which is shown in a progress bar on that foreground notification.
The point is that I want that int value to reach 150. so I am counting down how long it will take for the value which is given at the time of StartForeground() to reach 150 (which increases by 1 every 7 minutes) and showing the progress in the foreground notification with a time remaining (updated every second).
This all works fine... until i lock the screen and the phone presumably goes into "doze" or sleep mode. this then stops my timer or stops the service, not sure.
Question: How can I make this carry on working even if the device is locked/sleeping/dozed. I am using xamarin-android not forms.
Try to add the application to the whitelist.
You could use PowerManager.IsIgnoringBatteryOptimizations check whether this App in the system of the white list.
If not, you can apply for the permission by adding REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission to the Androidmanifest.xml and sending an Intent of ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS.
For example:
PowerManager powerManager = (PowerManager)GetSystemService(Context.PowerService);
if (!powerManager.IsIgnoringBatteryOptimizations(PackageName))
{
Intent intent = new Intent(Settings.ActionIgnoreBatteryOptimizationSettings);
StartActivity(intent);
}

Access recorded narrations programmatically

PowerPoint has a function named "Record narration". This records delays between user's button presses and then uses it to show automated slideshow, where animations, triggered to mouse-click, are shown according to those button clicks.
So, I want programmatically add this narrations. But in Microsoft::Office::Interop::PowerPoint I didn't find any useful data. How can I access these narrations programmatically?
Timings are recorded in a slide-level tag called TIMING
The tag value might be something like |7|5.8|5.6
Meaning, roughly, Start, wait 7 seconds, move to next click, wait 5.8 seconds ... and so on.
To see e.g. the TIMING tag contents for slide 1, this:
Msgbox ActivePresentation.Slides(1).Tags("TIMING")

Struggling to get ProgressBar updated (without threading)

i have a program(winform) that runs through a lot of files(in the area of 400 some times) in a folder and to show its progressing i use a progress bar. the info get posted into a listview if that makes a difference. The problem i am having is that when the pc is slow, im working with folders over a network or if it is a really big amount of files the ProgressBar just stops updating. if n leave the program it will continue and finish, but the progress bar gets stuck at some stage. And then only shows that it is complete (additional note: i have noticed that isnt just the progress bar. sometimes it is the whole form. but again, when the program is done it is fine. and while it is working you can move the form, just not interact with it)
Now here is where it gets tricky. I know it can be solved by using threads. i have however been told not to use it(let us not go into the why, lets just except it, whether it is stupid or not). i have also tried to refresh the form, and to refresh the bar itself. none of it seems to work. it isn't a good idea to use it, but even tried .DoEvent, it also doesn't work
How can i get the progress bar to update? any ideas?
here is some of the code i use for the progress bar
//before the loop
progress = iCount1;
progressvalue = 0;
double increment = 100 / (double)progress;
//this is at the end of the loop
progressvalue = progressvalue + increment;
then there is a bit of code. some of it to stop the value from going out of bound. the rest not related to the progress bar at all
edit: o, i have that 1 variable. and it basically runs over 3 loops. so that we have one continuous bar. not the bar running 3 times
edit: it seems to work fine for folder on my pc. but when it is run on a slow pc or over a network, that is when it does this
EDIT:Im getting answers about backgroundworker and threads. so is there no way to do it without threads?
Update: i finally convinced my boss to do it with backgroundworker. so ill be doing it in that. but for this question i guess the .DoEvent answer is the best
When the form-thread is busy, it will be very unresponsive and not draw the form at all. Even if you dont want threading i think you ought to reconsider..
I would use a backgroundworker as in this example: here it is a quite simple setup.
You could add an Application.DoEvents() then.
For example:
while(!end)
{
//You processing logic here
Application.DoEvents();
}
Note that it is generally discouraged since it will break the normal flow of events and may have unpredicted results.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx
http://www.codinghorror.com/blog/2005/08/is-doevents-evil-revisited.html

How to perform an action once every 1/2 second

I want a XAML page to perform an action once every 1/2 second.How would I do this?I'm thinking that I could use a Timer that starts when the page is loaded and resets once it gets to 500 milliseconds, but I'm not entirely sure how to do this.It doesn't have to be extremely precise.
You can use DispatcherTimer for example. For sample code look at documentation.
Did You Know… That You Can Create A Timer Using XAML Animation?

Speed-optimise a Windows Forms application

How do I speed optimize Windows Forms applications?
I am not talking about apparent .NET optimisation techniques - like NGEN-ing, caching objects, etc. I already tried that and what I am up to is to reduce the form initilization time from a 1500 msec down to 500 msec.
Profiling has identified the slowest code and almost all of it is in the InitializeComponent, and within this method the slowest lines is
creation of the (just new-ing) WebBrowser component
loading icon from a resource (hideous 500 msec)
creation of the ContextStripMenu
several this.Controls.Add() calls contribute a lot too.
At the moment, I can only see how to fix point (2) - move icon data from being stored as embedded resource to a private field (for example, Base64-encoded string).
What what should I do with points 1, 3 and 4?
Load the icon in a separate InitializeComponentAsync thread.
The only thing I can think of that you could do is rewrite the controls that you want to use and optimize them to initialize faster (as well as the Form class to optimize adding the adding of the controls to the form).
I can't see how that is feasible though, and I think you are going to be stuck with this, depending on your reliance on these controls.
One technique I have used in the past was to multi-thread the data load, so that it runs simultaneously to the form creation. In this instance data was being loaded out of AD, it cut about 1/3 of the load time.
I have changed the strategy of form loading, this will make a great change on form load timing, now it's taking an average of 37 ms instead of 466 ms.
Method: On First time Click on Top-tab/Icon, application load all form under that tab/icon and on click on Form Icon it will only switch visibility. And again visit on Top-tab will not load the form under that tab.
Just take another class like ClsAppearance.cs as I taken.
Initialize all controls like
static Infragistics.Win.Appearance txtBoxMidAppr = null;
I take my own name like txtBoxMidAppr instead if the appiarance1. due to it can be use for all textbox, by only once initialization.
Make a function where we can initialize the appearance and call it on the MDI/Main form loading only once.
public static void LoadAll()
{
txtBoxMidAppr = new Infragistics.Win.Appearance();
}
Make another function here and take the appearance code from designing window
public static Infragistics.Win.Appearance App_txtBoxMidAppr //text_box_small
{
get
{
txtBoxMidAppr.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(93)))), ((int)(((byte)(93)))), ((int)(((byte)(93)))));
txtBoxMidAppr.ImageBackground = global::CS_POS.Properties.Resources.text_box_small;
txtBoxMidAppr.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Stretched;
txtBoxMidAppr.ImageHAlign = Infragistics.Win.HAlign.Right;
return txtBoxMidAppr;
}
}
In the designing code of the form, comment all appearance setting of the text box and put the function name for getting appearance from the ClsAppearance.cs class
//appearance4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(93)))), ((int)(((byte)(93)))), ((int)(((byte)(93)))));
//appearance4.ImageBackground = global::CS_POS.Properties.Resources.text_box_small;
//appearance4.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Stretched;
//appearance4.ImageHAlign = Infragistics.Win.HAlign.Right;
this.uteNABoth.Appearance = CS_POS.App_Appearance.ClsAppearance.App_txtBoxMidAppr;
take all controls appearance and make a function in the class and call it from there.
So the appearance initialization will goes only once and can use many time.
Can you do lazy loading for your Webbrowser control? If it's in a tab which is not the main view then you might load webbrowser when that tab is activated.
Or you might load the form and then load the webbrowser (this might help you to show something first and then show everything, just like you'd do in a website).

Categories