עבור לתוכן

(vb.net 2010) איך לסגור תוכנית בצורה מסודרת

Featured Replies

פורסם

(שפת תכנות Visual Basic בסביבת עבודה Visual Studio 2010).

אהלן. אני משתמש בפקד Awesomium שעוזר לי ליצור דפדפן.

נעזרתי בקוד דוגמא שבא עם הSDK. הקוד לדוגמא מכיל חלון עם הפקד, שמציג לי form יחיד של הדפדפן awesomium. אני גולש באתרים, ואז בהפעלה נוספת של הקוד כל המידע נשמר לי.

החלטתי להעזר בקוד ולפתח אותו לכיוון של דפדפן שתומך בטאבים. הוספתי tabcontrol, וכל tab חדש משכפל לי את הform של דפדפן (בשם webform)

הכל עובד טוב עד שאני בא לסיים את התוכנית. אם אני סוגר את כל הforms ואז רושם end, התוכנה נסגרת, אבל המידע של הדפדפן, cookies, לא נשמרים.

כשאני מוסיף שורה לפני - webform.dispose, (שם החלון שמכיל את קוד הדפדפן), ואז מריץ את התוכנה, עושה שינויים, ומנסה לסגור את התוכנה - התוכנה פשוט נתקעת. אבל גם שומרת את הcookies בתיקית cache.

כלומר, עם שורת ה-webform.dispose אני מליח לשמור את נתוני הcookies, אבל התוכנה תקועה עד שאני לא סוגר אותה עם taskmanager. זאת אומרת, בכמה שניות הראשונות התוכנה שומרת את הcache, וכשהיא מסיימת, במקום לסגור את כל התוכנה, היא נשארת להיות במצב freeze.

השאלה שלי, מה אני מפספס כאן? איך אני סוגר נכון את הform של הדפדפן (חלון webform) כך שהתוכנה לא תתקע?

אם יש צורך, אעלה לכאן את כל הקוד.

נערך על-ידי Zeev86

פורסם
  • מחבר

מצטער :S

שפת תכנות Visual Basic בסביבת עבודה Visual Studio 2010.

קוד SDK נמצא ב- awesomium.com ואם יש צורך אני אעלה את כל הקוד שעליו אני מדבר לכאן (כשאחזור מעבודה), אבל עדיין יש צורך בSDK על מנת להפעיל את הקוד.

עריכה: אין לי אפשרות לערוך כותרת.

פורסם

אתה יכול לערוך את הכותרת, פשוט צריך לערוך במצב מתקדם את ההודעה הראשונה.

בכל מקרה יעזור אם תעלה את הקוד הרלוונטי, כי זה יהיה הרבה יותר ברור.

נערך על-ידי שניצל

פורסם
  • מחבר

צודק, ערכתי :)

אעלה את הקוד בערב כשאחזור מעבודה.

פורסם
  • מחבר

הנה הקוד.

ApplicationEvents.vb
------------------------------
Imports Awesomium.Core

Namespace My

' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication

Private Sub MyApplication_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
WebCore.Shutdown()
End Sub

End Class


End Namespace

Webform.vb
-----------------
'*******************************************************************************
' Project : Awesomium.NET (VBWebControlSample)
' File : WebForm.vb
' Version : 1.7.0.0
' Date : 3/5/2013
' Author : Perikles C. Stephanidis (perikles@awesomium.com)
' Copyright : ©2013 Awesomium Technologies LLC
'
' This code is provided "AS IS" and for demonstration purposes only,
' without warranty of any kind.
'
'-------------------------------------------------------------------------------
'
' Notes :
'
' Simple Visual Basic sample demonstrating the use of the Windows Forms
' WebControl
'
'
'*******************************************************************************

Imports Awesomium.Core
Imports Awesomium.Windows.Forms

Public Class WebForm

Private _IsChild As Boolean

Public Sub New()
MyClass.New(False)
End Sub

Public Sub New(isChild As Boolean)

' This call is required by the designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
_IsChild = isChild

If Not isChild Then
If Not WebCore.IsRunning Then
WebCore.Initialize(New WebConfig() With {.LogLevel = LogLevel.Verbose})
End If

MyWebControl.Source = New Uri("http://www.youtube.com")
End If

' Note how we set a WebSession for our WebControl, by using the new WebSessionProvider
' in the designer.

' Assign the source for our bindings.
IWebViewBindingSource.DataSource = CType(MyWebControl, IWebView)
End Sub

Public ReadOnly Property IsChild() As Boolean
Get
Return _IsChild
End Get
End Property

Private Sub MyWebControl_ShowCreatedWebView(sender As Object, e As ShowCreatedWebViewEventArgs) Handles MyWebControl.ShowCreatedWebView
' Create an instance of our application web form, that will
' host the new view instance, either we wrap the created child view,
' or we let the WebControl create a new underlying web-view.
Dim newForm As New WebForm(True)

' Treat popups differently. If IsPopup is true, the event is always
' the result of 'window.open' (IsWindowOpen is also true, so no need to check it).
' Our application does not recognize user defined, non-standard specs.
' Therefore child views opened with non-standard specs, will not be presented as
' popups but as regular new windows (still wrapping the child view however -- se below).
If e.IsPopup AndAlso Not e.IsUserSpecsOnly Then
' JSWindowOpenSpecs.InitialPosition indicates screen coordinates.
Dim screenRect As Rectangle = e.Specs.InitialPosition.ToRectangle()

' Set the created native view as the underlying view of the
' WebControl. This will maintain the relationship between
' the parent view and the child, usually required when the new view
' is the result of 'window.open' (JS can access the parent window through
' 'window.opener'; the parent window can manipulate the child through the 'window'
' object returned from the 'window.open' call).
newForm.MyWebControl.NativeView = e.NewViewInstance
' Do not show in the taskbar.
newForm.ShowInTaskbar = False
' Set border style based on specs.
newForm.FormBorderStyle = If(e.Specs.Resizable, FormBorderStyle.SizableToolWindow, FormBorderStyle.FixedToolWindow)

' Show the form.
newForm.Show()

' If the caller has not indicated a valid size for the new popup window,
' let it be opened with the default size specified at design time.
If Not screenRect.Size.IsEmpty Then
' Specify the indicated size.
newForm.ClientSize = screenRect.Size
End If

' If the caller has not indicated a valid position for the new popup window,
' let it be opened in the default position specified at design time.
If Not screenRect.Location.IsEmpty Then
' Move it to the specified coordinates.
newForm.DesktopLocation = e.Specs.InitialPosition.ToRectangle().Location
End If

ElseIf e.IsWindowOpen OrElse e.IsPost Then
' No specs or only non-standard specs were specified, but the event is still
' the result of 'window.open' or of an HTML form with tagret="_blank" and method="post".
' We will open a normal window but we will still wrap the new native child view,
' maintaining its relationship with the parent window.
newForm.MyWebControl.NativeView = e.NewViewInstance
' Show the form.
newForm.Show()
Else
' The event is not the result of 'window.open' or of an HTML form with tagret="_blank"
' and method="post"., therefore it's most probably the result of a link with target='_blank'.
' We will not be wrapping the created view; we let the WebControl hosted in ChildWindow
' create its own underlying view. Setting Cancel to true tells the core to destroy the
' created child view.
'
' Why don't we always wrap the native view passed to ShowCreatedWebView?
'
' - In order to maintain the relationship with their parent view,
' child views execute and render under the same process (awesomium_process)
' as their parent view. If for any reason this child process crashes,
' all views related to it will be affected. When maintaining a parent-child
' relationship is not important, we prefer taking advantage of the isolated process
' architecture of Awesomium and let each view be rendered in a separate process.
e.Cancel = True
' Note that we only explicitly navigate to the target URL, when a new view is
' about to be created, not when we wrap the created child view. This is because
' navigation to the target URL (if any), is already queued on created child views.
' We must not interrupt this navigation as we would still be breaking the parent-child
' relationship.
newForm.MyWebControl.Source = e.TargetURL
' Show the form.
newForm.Show()
End If
End Sub

Private Sub MyWebControl_WindowClose(sender As Object, e As WindowCloseEventArgs) Handles MyWebControl.WindowClose
If IsChild Then
Me.Close()
ElseIf Not e.IsCalledFromFrame AndAlso (MsgBox("This page is asking to close the application window. Do you confirm?", MsgBoxStyle.YesNo, MyWebControl.Source) = MsgBoxResult.Yes) Then
Me.Close()
End If
End Sub
End Class



Browser.vb
---------------
Public Class Browser

Private Sub Browser_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
'WebForm.IWebViewBindingSource.Dispose()
'WebForm.MainWebSessionProvider.Dispose()
'MsgBox("closing")
'Me.Visible = False
'For Each proc As Process In System.Diagnostics.Process.GetProcesses
' If proc.ProcessName = "VBWebControlSample" Then
' If proc.Responding = True Then
' ' attempt to kill the process
' 'proc.Kill()
' 'End
' ' try to start it again
' 'System.Diagnostics.Process.Start(proc.StartInfo)
' End If
' End If
'Next
WebForm.Dispose()
'Me.Close()
'WebForm.Close()

Do While WebForm.Disposing = True

Loop

If CType(WebForm, Form).IsDisposed Then
Me.Close()
WebForm.Close()
'do something
End If



'Me.Close()
End Sub

Private Sub Browser_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim frm As New WebForm()
frm.TopLevel = False
frm.Parent = Me.TabControl1.TabPages(Me.TabControl1.SelectedIndex)
frm.Show()
frm.Size = New Size(Me.TabControl1.Size.Width, Me.TabControl1.Size.Height)
End Sub

End Class

Webform.vb זה הדפדפן. אם אני מריץ אותו כFORM ראשי, אני גולש, סוגר תוכנה בלי בעיה. מפעיל מחדש, גולש, כל הנתונים נשמרו בתיקיית cache.

Browser.vb. הדפדפן שאותו אני רוצה לעשות. כל TAB אני צריך שיעשה dublicate ל-webform ומכאן מתחילה הבעיה. כשאני סוגר את התוכנה איך שנכתב בקוד, התוכנה לא מגיבה. שומרת, אבל לא מגיבה עד שאני סוגר אותה בכוח.

קישור לקבצי פרויקט: http://www.gptv.co.il/sample.zip

SDK של הדפדפן: http://awesomium.com/downloads/awesomium_1_7_1_sdk_win.exe

נערך על-ידי Zeev86

פורסם

למיטב זכרוני אם עושים Show ל-Form אז אסור לעשות לו Dispose. סוגרים אותו רק עם Close. יכול להיות שזה עושה לך את הבעיה.

פורסם
  • מחבר

עשיתי את כל הקומבינציות האלה שום דבר לא עזר.

עכשיו עליתי על משהו. אני צריך לעשות על כל TAB

CType(TabControl1.SelectedTab.Controls.Item(0), WebForm).Dispose()

וזה עושה לו dispose ואז המידע נשמר D:

אבל עכשיו אני נתקל בבעיה נוספת. כשאני רוצה לשנות כתובת בצורה הבאה:

CType(TabControl1.SelectedTab.Controls.Item(0), Awesomium.Windows.Forms.WebControl).Source = New Uri("www.google.com")

זה רושם לי:

Unable to cast object of type VBWebControlSample.WebForm to type Awesomium.windows.forms.webform

ידוע לך אולי מה אני צריך לרשום במקום Awesomium.Windows.Forms.Webcontrol? ניסיתי WebForm וזה בכלל לא נותן להריץ את הקוד ורושם source is not a member of VBwebcontrolSample.WebForm.

נערך על-ידי Zeev86

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים