none
how to save the state of code if anything happen by mistake RRS feed

  • Question

  • i have a long code it take 3 to 5 minutes to complete so i face a big problem if anything happen when the process not completed

    what i can do in this situation please help

    Tuesday, June 16, 2020 4:25 PM

All replies

  • Hi

    Again, your question is not clear.

    For example, if yourbuildingcollapses on top of your computer duringprocess, there isn't much you can do about it!

    Explain more clearly what problem you have.


    Regards Les, Livingston, Scotland

    Tuesday, June 16, 2020 4:32 PM
  • Hello,

    There is an API for this ApplicationRecoveryManager, RecoveryData, RecoverySettings part of the Windows-API-Pack that are not intuitive but worth a look at.

    Code is in C#

    https://github.com/aybe/Windows-API-Code-Pack-1.1


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, June 16, 2020 6:49 PM
    Moderator
  • 3 to 5 minutes to complete? What are  you talking about? Are talking about compiling the code?
    Tuesday, June 16, 2020 10:05 PM
  • not compiling the code its about the database because its so heavely doing many process to it so it take time to make some calculation and update also insert it make it probably 3min or more

    Wednesday, June 17, 2020 8:53 AM
  • my idea was to point probably where the process stopped

    my code consist of 2 loop, inside it a lot of calculation and interaction with the datatbase probably 5 table

    i think to point with a text file perhaps

    if the one process complet go to textfile and write ok

    and go to next process if finiched go to textfile and write ok

    if something happen  the text file will rescue the job with all line with ok that mean process complet

    and if i want to complet the rest of the process just take the line in text file that didn't have the ok

    i hope this clearify my idea

    Wednesday, June 17, 2020 9:18 AM
  • Hi

    Here is some code which would write a Log to a file (Path is set to a DeskTop text file)

    In Sub Two, there is an error created specifically to show how to wrap code in a Try ... Catch block.

    This is a stand alone project example and can be tried out. It would need a new project with an empty ListBox1 on Form1 and copy/replace Form1 code with this code.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim path As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Log.txt")
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        My.Computer.FileSystem.WriteAllText(path, "Started  OK" & vbCrLf, True)
    
        One()
        Two()
        Three()
      End Sub
      Sub One()
        My.Computer.FileSystem.WriteAllText(path, "Sub one exit OK" & vbCrLf, True)
      End Sub
      Sub Two()
        Dim errorhere As String
        Try
          ' create an error here
          ' the ListBox is EMPTY
          errorhere = ListBox1.Items(11).ToString
          My.Computer.FileSystem.WriteAllText(path, "Sub Two exit OK" & vbCrLf, True)
        Catch ex As Exception
          My.Computer.FileSystem.WriteAllText(path, "Sub Two Failed with " & ex.Message & vbCrLf, True)
        End Try
      End Sub
      Sub Three()
        My.Computer.FileSystem.WriteAllText(path, "Sub Three exit OK" & vbCrLf, True)
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Wednesday, June 17, 2020 11:03 AM
  • my idea was to point probably where the process stopped

    my code consist of 2 loop, inside it a lot of calculation and interaction with the datatbase probably 5 table

    i think to point with a text file perhaps

    if the one process complet go to textfile and write ok

    and go to next process if finiched go to textfile and write ok

    if something happen  the text file will rescue the job with all line with ok that mean process complet

    and if i want to complet the rest of the process just take the line in text file that didn't have the ok

    i hope this clearify my idea

    No that does not solve anything.

    First thing to know is why it can stop running. Normally that should not happen. 

    And because there is a database involved, you can not solve anything if your process is so lousy that it can go down. With a database there is normally not 1 user but more and their work is than also damaged if your program is inferior. 


      

    Success
    Cor


    Wednesday, June 17, 2020 12:53 PM
  • not compiling the code its about the database because its so heavely doing many process to it so it take time to make some calculation and update also insert it make it probably 3min or more

    You would have to show code and explain what you are doing in order for anyone to help, becuase otherwise, they are just shooting in the dark with posts.
    Wednesday, June 17, 2020 3:12 PM