|
I think you can. But I've always heard that crossing over threads is not the best, though.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
yes but before you can access the textbox properties, you must do an invoke to get the population of the textbox onto the main thread...
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
I'd like to be able to load an assembly and then unload it, thereby allowing the user to edit and recompile the assembly (via Codeprovider). Then I want to reload the new recompiled assembly.
But the unload statement below doesn't free the .dll so that I can write to it again.
Is there a way to do this?
thank you!
Dim SubDomain As AppDomain
Dim as1 As Assembly = Reflection.Assembly.ReflectionOnlyLoadFrom(TypeToOpen & ".dll")
StrategyClass = SubDomain.CreateInstanceAndUnwrap(as1.FullName, "Strategies.Strategy")
AppDomain.Unload(SubDomain)
|
|
|
|
|
Hi,
AFAIK AppDomain.Unload is the only way to get rid of a loaded DLL.
|
|
|
|
|
Hello every one
I am new in vb.net and i am doing one simple application to save text file, and i have provide choice to display image in picture box but i am not saving image in file file can only save students name,age,class etc but i am haveing problem to save file,but if i dont load image in picture box then it's works fine again i am not saving image in file it's just for selecting image from file
can some one please help me with this
code is some thing like this (for creating profile)
Private Sub btnProfile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProfile.Click<br />
Dim Response As DialogResult<br />
Dim Age As String<br />
Dim MyString, MidString, MidString2 As String<br />
'get first leter in upper case for text box for name <br />
txtName.Text = StrConv(txtName.Text, VbStrConv.ProperCase)<br />
If Trim(txtName.Text) = "" Then<br />
Response = MessageBox.Show("Please enter your name", "Error", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Error)<br />
If Response = DialogResult.OK Then<br />
txtName.Focus()<br />
Exit Sub<br />
End If<br />
End If<br />
Age = Str(DateDiff("yyyy", DOB, Now))<br />
Message = "Your profile was created on " + ((Format(DateTime, "d MMMM yyyy") + _<br />
" at " + Format(DateTime, "hh : mm tt" + ControlChars.Cr)))<br />
Message += "" + ControlChars.Cr<br />
Message += txtName.Text + " is a student in the " + cboGrade.Text + " grade " + ControlChars.Cr<br />
If rdoMale.Checked Then<br />
Message += "He is " + Age + " years old" + ControlChars.Cr<br />
ElseIf rdoFemale.Checked Then<br />
Message += "She is " + Age + " years old" + ControlChars.Cr<br />
End If<br />
If picStudent.Image Is Nothing Then<br />
Message += "" + ControlChars.Cr<br />
Message += "No picture added " + ControlChars.Cr<br />
Else<br />
Message += "" + ControlChars.Cr<br />
Message += "Your picture was also added in your profile" + ControlChars.Cr<br />
End If<br />
Response = MessageBox.Show(Message, "Student Profile", MessageBoxButtons.OKCancel, _<br />
MessageBoxIcon.Information)<br />
'Add data in to student data file<br />
Call AddStudentData()<br />
'Add student name in to cobmobox<br />
Call AddDataToCombo()<br />
If Response = DialogResult.OK Then<br />
Response = MessageBox.Show("Would you like to creat another profile", "New profile", _<br />
MessageBoxButtons.YesNo, MessageBoxIcon.Question)<br />
'if cancel then reset form<br />
ElseIf Response = DialogResult.Cancel Then<br />
txtName.Text = ""<br />
cboGrade.SelectedIndex = 0<br />
txtName.Focus()<br />
nudDay.Value = 1<br />
dudMonth.SelectedIndex = 0<br />
nudYear.Value = 1951<br />
picStudent.Image = Nothing<br />
Exit Sub<br />
End If<br />
'if new profile and yes then reset form<br />
If Response = DialogResult.Yes Then<br />
txtName.Text = ""<br />
cboGrade.SelectedIndex = 0<br />
txtName.Focus()<br />
nudDay.Value = 1<br />
dudMonth.SelectedIndex = 0<br />
nudYear.Value = 1951<br />
picStudent.Image = Nothing<br />
Exit Sub<br />
End If<br />
If Response = DialogResult.OK Then<br />
txtName.Text = ""<br />
cboGrade.SelectedIndex = 0<br />
txtName.Focus()<br />
picStudent.Image = Nothing<br />
Else : Me.Close()<br />
End If<br />
End Sub
and code for loading image in picture is
Private Sub btnPicture_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPicture.Click<br />
'load picture of student<br />
If dlgOpen.ShowDialog = DialogResult.OK Then<br />
picStudent.Image = Image.FromFile(dlgOpen.FileName)<br />
End If<br />
End Sub
and code for saving students profile,display profile and add students name in combo box is like this
Private Sub AddStudentData()<br />
Dim DataWriter As StreamWriter<br />
FileName = Trim(txtName.Text) + ".txt"<br />
DataWriter = File.CreateText("StudentData\" + FileName)<br />
DataWriter.WriteLine(Message)<br />
DataWriter.Close()<br />
cboData.Items.Add(FileName)<br />
<br />
End Sub<br />
Private Sub AddDataToCombo()<br />
cboData.Items.Clear()<br />
Dim files() As String = Directory.GetFiles(Application.StartupPath + "\StudentData")<br />
For i As Integer = 0 To files.Length - 1<br />
cboData.Items.Add(Path.GetFileNameWithoutExtension(files(i)))<br />
Next<br />
If files.Length = 0 Then<br />
cboData.Text = "Empty Student Database"<br />
Else<br />
cboData.Text = "Select name to display profile"<br />
End If<br />
End Sub<br />
Private Sub DisplayData()<br />
Dim DataReader As StreamReader<br />
DataReader = File.OpenText("StudentData\" + cboData.SelectedItem.ToString + ".txt")<br />
FileName = DataReader.ReadToEnd<br />
MessageBox.Show(FileName, "Student Database", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
DataReader.Close()<br />
End Sub
any help please
have a nice X-mas and new year to all
thanks
|
|
|
|
|
Instead of posting the entire code, just post the trouble spot. What is the problem you are having?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
The Image.FromFile method locks the file the image was created from for the lifetime of the Image object you created.
Look into using Image.FromStream instead.
|
|
|
|
|
I think I spot a problem with your reply... :P
Dave Kreskowiak wrote: The Image.FromStream method locks the file
Dave Kreskowiak wrote: Look into using Image.FromStream instead.
:P
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Whoops! Hey, someone reads my reply's!! They really, really do!
|
|
|
|
|
Hello sir
sorry for late
but sir i dont know how to correct this error, again i dont want to save image in file it's just for display so i dont select image then it's works fine but if i select image then it's a problem so sir can you please tell me more how to solve this problem as you said look in to using Image.FromStream
so i am confuse
waiting for your kind rep.
wish you very happy new year
thanks
|
|
|
|
|
Let me repeat myself. When you try to write over a file that's already open, you'll get this error. When you use Image.FromFile to load an image, Image will lock that file open for the lifetime of the Image object. Use Image.FromStream to get the data from the file and the file won't be locked.
|
|
|
|
|
hello sir
thanks for your kind rep.
you mean do i need to do some thing like this
picStudent.Image = Image.FromStream(dlgOpen.FileName)
to open the image or some thing else
like i said before i am not saveing image in file it's just for display image in picture box that's what my assignment says, what i need to save only customer's details only,if i save only details then it's works fine,
but sir still i am confuse
waiting for your kind rep.
thanks
|
|
|
|
|
Have you ever used the FileStream class to open files??
|
|
|
|
|
hello sir
as i said i am new in vb.net and i am learning so i dont know much about this, and as you said try to use Image.FileStream and when i open file from file dialog box it looks files which is all ready open so i am confuse there that which file is open, like in this project when i click btnProfile it's create file to store and with out image it's works fine, but if i load image from dlgOpen then it's problem, but dlgOpen is different and write file from StreamWriter is different that's what i understand but i am not sure that i am right or wrong so please sir can you tell me some thing more about this, and i am sure that you have found that problem but i am not getting there that's the only problem
waiting for your kind rep.
have a nice day
thanks
|
|
|
|
|
bapu2889 wrote: and when i open file from file dialog box it looks files which is all ready open
What?? This doesn't make any sense. I think you have a mistaken idea about how the OpenFile dialog works. All it does is return a string representing the path to a file. It doesn't acutally open the file, unless you speicifically tell it to AFTER the dialog returns to your code.
All you do to open a file using FileStream is:
Dim fs As New FileStream(filePath)
Dim pic As Bitmap = Image.FromStream(fs)
fs.Close()
fs.Dispose()
Image file is locked when you set the PictureBox Image property to a file[^]
|
|
|
|
|
hello sir
first of all thanks for quick rep.
now i will try to fix this problem
thanks again
have a nice day
wish you very happy new year
|
|
|
|
|
Sorry, dumb question here.
If I make a method in a class it is not a shared method and needs to be instantiated.
If I make a method in a form it becomes a shared method and does not need to be instantiated.
I want to call these methods from various places in my code, perhaps even from different threads at the same time.
It's easier to call a shared method because there's no need to instantiate it. But does doing so create the possibility of more than one thread calling the method at the same time thus creating problems?
In short, should I instantiate all of my method calls, even to the shared methods in a form?
Thanks, and Happy Holidays all!
|
|
|
|
|
You can put the word "shared" in your routine definitions to make them shared.
Public Class Example<br />
Public Shared Sub See()<br />
'this is a shared routine<br />
End Sub<br />
End Class
Use:
Example.See << no instantiance...
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
Right, but not my question.
Question: Is it safe to call a shared method from multiple threads? I'm concerned that the shared method might be called by more than one thread at the same time.
|
|
|
|
|
cstrader232 wrote: Question: Is it safe to call a shared method from multiple threads? I'm concerned that the shared method might be called by more than one thread at the same time.
In general, yes. But it depends on what the shared method code is doing.
|
|
|
|
|
yes that is a concern but like dave said it depends on what it's doing. you can use synclock to make sure one thread executes a chuck of code at at time...
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
cstrader232 wrote: If I make a method in a form it becomes a shared method and does not need to be instantiated.
False. The method becomes Shared only if you specify it in the method definition.
|
|
|
|
|
Wait! What am I missing -- it looks to me like methods in forms by default ARE shared:
Dim A below creates an error:
Error 93 Reference to a non-shared member requires an object reference.
Dim B below does not
Class Worker
Sub Work()
Dim A = TestClass.test
Dim B = TestClass2.test
End Sub
End Class
Public Class TestClass
Function test()
Return 99
End Function
End Class
Public Class TestClass2
Inherits System.Windows.Forms.Form
Function test()
Return 99
End Function
End Class
|
|
|
|
|
why do you say that? if you got an error when trying to access a function that's not shared. you get an error? why do you feel they are defaulted?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
|
|
|
|
|
Well what I noticed was that if the class inherits from system.windows.forms.form then my test function in my code didn't need to be instantiated. However, if the class does not inherit from system.windows.forms.form then the test class did need to be instantiated.
|
|
|
|