Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

need a new method of doing a wait task delay

Hello there HF, I am having issues with my project, I am currently stuck using a framework 3.5 due to obfuscation methods. The problem I got is I need a new way of using a await Task.Delay from my tray pop ups. for it to fade in and fade out.

Code
private PopupDesign popupDesign1;
        private Timer timer1;
        private System.ComponentModel.IContainer components;
        private Timer timer2;
        private Timer timer3;
        public static int CurrentNots = 0;
        public static void addNote() { CurrentNots++; }
        public static void remNote() { if (CurrentNots != 0) CurrentNots--; }



        private  void FadeIn(Form o, int interval = 80) {
            while (o.Opacity < 1.0) {
              
               await Task.Delay(interval);
                o.Opacity += 0.05;
            }
            o.Opacity = 1;
            await Task.Delay(2000);
            FadeOut(o, interval);
        }

        private async void FadeOut(Form o, int interval = 80) {
            while (o.Opacity > 0.0) {
               await Task.Delay(interval);
                o.Opacity -= 0.05;
            }
            o.Opacity = 0;
            remNote();
        }

        public static Rectangle getScreen(Form o) {
            return Screen.FromControl(o).Bounds;
        }

        public static int calculateLocation(Form o) {
            return (getScreen(o).Height - 40) - ((62 + 15) * CurrentNots);
        }

        public Tray(
            string title, string message,
            PopupDesign.Kind kind = PopupDesign.Kind.Comp, Image image = null) {
            InitializeComponent();

            popupDesign1.Text = title;
            popupDesign1.Description = message;
            popupDesign1.Type = kind;
            popupDesign1.Image = image;

            addNote();
            this.Location = new Point(getScreen(this).Width - Width - 20, calculateLocation(this));
            this.Opacity = 0;
            this.Show();
            FadeIn(this, 20);
        }

Could any help with this please :)
then run that from a thread itself
(May 17, 2016 07:11 AM)+Haze Wrote:  then run that from a thread itself
I already tried this and it just freeze the tool for the length I put it to sleep for but nothing pop ups or happens.
(May 17, 2016 08:07 AM)AspectModding Wrote:  I already tried this and it just freeze the tool for the length I put it to sleep for but nothing pop ups or happens.

Show the code.

You're probably still sleeping the main thread, you have to execute the popup stuff on a different thread, and sleep that thread.
Easy way is pinvoke AnimateWindow, it supports fade animations. This should help get you started: https://github.com/oduslabs/TrayNotifica...nimator.cs
(May 17, 2016 08:07 AM)AspectModding Wrote:  I already tried this and it just freeze the tool for the length I put it to sleep for but nothing pop ups or happens.

Not possible for it to freeze the main thread unless you're joining with the main UI thread in which case you aren't properly threading.

I guess the AnimateWindow() function would be an easy approach.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
You should check Odus's project but here's an alternative delay method:

PHP Code

<?php 
private void Wait(int timeout)
{
    
using (AutoResetEvent AREv = new AutoResetEvent(false))
        
AREv.WaitOne(timeout, true);
} 
(May 17, 2016 01:54 PM)PavilionVI Wrote:  You should check Odus's project but here's an alternative delay method:

PHP Code

<?php 
private void Wait(int timeout)
{
    
using (AutoResetEvent AREv = new AutoResetEvent(false))
        
AREv.WaitOne(timeout, true);
} 

Aside from the poor naming consistency...

You're not using this for any thread synchronization so this is really a waste. This calls Dispose() for that object to deal with things that don't even matter here... Thus this is a poor idea - instantiating a class meant for something entirely different, and then disposing of it with each function call. Thread Sleep() would have done a better job here
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by ChaosComputerDudeJan 21, 2020 04:23 AM 0 127 Jan 21, 2020 04:23 AM
Last Post: ChaosComputerDude
[C#] by sososeriousSep 15, 2017 10:55 AM 7 385 Sep 15, 2017 10:55 AM
Last Post: sososerious
[Shell] by PhloxMar 26, 2017 06:46 PM 2 195 Mar 26, 2017 06:46 PM
Last Post: Phlox