Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Midnight Ahri

@Midnight Ahri
About
Posts
126
Topics
39
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • showing form from bottom wth timer
    M Midnight Ahri

    yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.

    C# help

  • showing form from bottom wth timer
    M Midnight Ahri

    I've put the comment on where to change the delay. And I changed the interval to 1000 so the tick event execute every 1 second. So you don't have to change the interval anymore.

    C# help

  • CreateKey
    M Midnight Ahri

    I'm pretty sure no one is going to open that link.

    C# com

  • showing form from bottom wth timer
    M Midnight Ahri

    Edit : I changed your code but yeah it's messy. My advice, * Reduce timer usage * Stop your timer when you don't need them (not keep returning)

    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    timer3.Interval = 1000;
    }

        bool flag = true;
        int delay = 0;
    
        private void Form1\_Load(object sender, EventArgs e)
        {
            this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
            this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
            // to make it in the corner + this.height
    
            timer1.Enabled = true;
        }
    
        private void timer1\_Tick(object sender, EventArgs e)
        {
            flag = true;
            if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
            {
                this.Top = this.Top - 10;
            }
            else
            {
                timer1.Enabled = false;
            }
        }
    
        private void timer2\_Tick(object sender, EventArgs e)
        {
            flag = false;
            if (this.Top > Screen.PrimaryScreen.Bounds.Height)
            {
                timer2.Enabled = false;
                timer3.Enabled = true;
                return;
            }
    
            else
            {
                this.Top = this.Top + 10;
                flag = true;
            }
        }
    
        private void button1\_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
        }
    
        private void timer3\_Tick(object sender, EventArgs e)
        {
            if (this.delay >= 5) //delay for 5 second
            {
                this.delay = 0;
                timer1.Enabled = true;
                timer3.Enabled = false;
            }
            else
            {
                this.delay += 1;
            }
        }
    }
    
    C# help

  • showing form from bottom wth timer
    M Midnight Ahri

    Maybe you didn't start your timer? :doh:

    C# help

  • Auto Connect SQLConnection
    M Midnight Ahri

    Richard MacCutchan wrote:

    So you want us to guess a) what your code is doing, and b) what errors occur.

    I've explained everything about my code. I'm just asking about why the sql queue up. By the way, thank you very much. At least you teach me async and await technique. And I appreciate that. I'm not good at programming, so maybe I'll ask you something again. See ya. :thumbsup:

    C# help database sysadmin data-structures career

  • problem with time field in MySQL
    M Midnight Ahri

    Maybe this[^] could help you.

    C# help database mysql com announcement

  • Auto Connect SQLConnection
    M Midnight Ahri

    Oh cmon, I tried a lot of example and still not working. I'm really really stuck here. I'm not asking someone to do the code for me, at least tell me what is wrong in my code. Please :(

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    Thank you very much for your instruction, This is what I done.

    private void SQLClientLoader_Load(object sender, EventArgs e)
    {
    this.GetSQLState();
    }

    async private System.Threading.Tasks.Task GetStateAsync()
    {
    do
    {
    this.cts = new CancellationTokenSource();
    this.cnn = new SqlConnection(this.par.Constr);

                try
                {
                    await Task.Delay(2500);
    
                    await this.cnn.OpenAsync(cts.Token);
                }
                catch (Exception ex)
                {
                    cts.Cancel(false);
    
                    this.cnn.Dispose();
                    this.cts.Dispose();
                }
            } while (this.cnn.State != ConnectionState.Open);
    
            return this.cnn.State;
        }
    

    async private void GetSQLState()
    {

            if (await GetStateAsync() == ConnectionState.Open)
            {
                this.Close();
            }
    
            await Task.Delay(2500);
        }
    

    It's working. I used cancellation token, but why the OpenAsync() is not cancelled and still queue up? Edit : Found my solution. Clear the connection pool, made my day guys. Thank you helping me. :laugh:

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    This is what I do,

    static async Task Method(SqlConnection cnn)
    {
    await cnn.OpenAsync();
    return cnn.State;
    }

    private void SQLClientLoader_Load(object sender, EventArgs e)
    {
    do
    {
    this.cnn = new SqlConnection(this.par.Constr);

                try
                {
                    ConnectionState cst = Method(cnn).Result;
    
                    if (cst == ConnectionState.Open)
                    {
                        this.par.sqSuccess = true;
                    }
                    else
                    {
    
                    }
                }
                catch (Exception ex)
                {
                    this.par.sqSuccess = false;
    
                    this.par.Exception = ex.Message;
                }
                finally
                {
    
                }
            } while ((bool)this.par.sqSuccess != true);
        }
    

    It freeze my application everytime I this form load executed. Should I combine Task with BackgroundWorker to prevent freeze? Or maybe something is wrong in my code? Can you explain to me cause I'm new and confuse of this.

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    Thank you very much, I'm new to task and just found it today. But I'll keep searching.

    After calling OpenAsync, State must return Connecting until the returned Task is completed. Then, if the connection was successful, State must return Open. If the connection fails, State must return Closed.

    Sorry that english is not my first language and I'm not that good in programming. So what I understand above is like this.

    this.cnn.OpenASync();

    if (this.cnn.State == ConnectionState.Connecting)
    {
    //cnn is busy connecting
    }

    Then if it's busy, then I will return; instead of OpenASync() again.

    if (this.cnn.State == ConnectionState.Closed)
    {
    //cnn failed to open
    }

    And if it's closed, then I assume cnn failed and finished processing. But it's not working. It's ok, I'll search about task. Thank you very much btw. :)

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    Oh ok ok. There are no example of code inside but I will try googling. Thank you very much. :)

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    It uses System.Threading.Task. Is it possible if I want to use it with backgroundworker?

    C# help database sysadmin data-structures career

  • Auto Connect SQLConnection
    M Midnight Ahri

    So I've been stuck here for 1 week. Everytime I had problem in SQL connection (ex. someone switch of server) my application will show exception message in a messagebox. I don't know when will the connection available except I keep trying to open the connection / execute a query. So I create a wait form that will appear if connection is unavailable, keep trying to open the connection, and close itself when connection is available again. To hide the freeze from user, I use backgroundworker. This is the backgroundworker code

    private void StartLoader(object sender, DoWorkEventArgs e)
    {
    for (int i = 1; i <= 10; i++)
    {
    if (this.par.sqSuccess) //if no error, means connection is available, stop looping
    {
    break;
    }
    else
    {
    i -= 1;
    }

                System.Threading.Thread.Sleep(5000); //report progress every 5 second
            }
    

    This is the backgroundworker progress changed event

            this.cnn = new SqlConnection(this.par.Constr);
    
            try
            {
                this.cnn.Open(); //SqlConnection
    
                this.par.sqSuccess = true; //if no error, then I change this variable
            }
            catch (Exception ex)
            {
                this.par.Exception = ex.Message;
            }
            finally
            {
                if (this.cnn != null) { this.cnn.Dispose(); }
            }
            if (this.par.sqSuccess) { this.Close(); }
    

    After everything is complete, I tried to stop SQL service from services.msc, then I try to connect. The wait form will appear and keep doing its job. A few second after I try to connect, I start the service again and the wait form did close, success. This is the problem, when I wait a little bit longer before I start the service again, the wait form still closed, but it takes a while. After I check everything, it seems like the cnn.open() queue up and the longer I stop the service, the longer it takes for the wait form to close. I searched google and try to add Connect Timeout=3; behind my connection string, as I'm sure my thread.sleep(5000) won't make them queue up, but still not working. I need help to understand how this cnn.open works, why this is not working, what happen in this code that makes I got this problem. While processing the cnn.open(), did my application

    C# help database sysadmin data-structures career

  • Put DLL file to another location
    M Midnight Ahri

    I always put component dll in Application.StartupPath so user is able to run the application. Is it possible to put it to another location to keep the application working? Example location:

    Application.StartupPath + @"\DLL\"

    Edit: I found this but I don't really understand it. http://stackoverflow.com/questions/2445556/c-sharp-putting-the-required-dlls-somewhere-other-than-the-root-of-the-output[^]

    C# com tutorial question

  • Application Settings
    M Midnight Ahri

    lukeer wrote:

    "Documents and Settings/$YourUserName$/Application Data/$Company$/$ApplicationNameWithSomeAlphaNumericFuzz$/$ProductVersion$/user.config"

    I found this but nothing inside.

    "C:\Documents and Settings\Administrator\Application Data\Microsoft Corporation\Microsoft (R) Visual Studio (R) 2010\1.0.30319.1"

    There are no strange company name in Application Data. Btw thank you for answering. Edit : I found it here[^] It's just like what you answered, I missed Local Settings before Application Data. Thank you very much. :)

    C# csharp visual-studio debugging question

  • Application Settings
    M Midnight Ahri

    private void button1_Click(object sender, EventArgs e)
    {
    Properties.Settings.Default.Constr = this.textBox1.Text;
    Properties.Settings.Default.Save();
    }

        private void Form1\_Load(object sender, EventArgs e)
        {
            this.textBox1.Text = Properties.Settings.Default.Constr;
        }
    

    Constr is the setting I create. Actually I'm going to put licensing there too, of course I will encrypt it before I save. Now I still can't find it. This is what I use > http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx[^]

    C# csharp visual-studio debugging question

  • Application Settings
    M Midnight Ahri

    I'm new to this, or precisely just realize that visual studio had this in the properties folder below visual studio project. I'm planning to put important things like connection strings inside. I tried to save a simple text in the setting and save it. When I run the application, in the debug folder appear "WindowsFormsApplication1.exe.config" file. I know that it's the setting I created, but the value of the setting is not inside. When I re-run the application, it was able to load the text i saved before. Where did the setting save the value? :omg: Btw sorry for bad english.

    C# csharp visual-studio debugging question

  • Grid Based Games
    M Midnight Ahri

    Thank you very much for the help. I will try to understand it as I never use get set or that kind of class.

    C# css help tutorial question

  • Grid Based Games
    M Midnight Ahri

    I understand how to create animation like pacman, but to move the pacman, I can only think of using location. Problem is, how could I know there is obstacle or not?

    C# css help tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups