|
Greeting,
I want to know to code an application to be multi-threaded one and each thread run on different processor using Visual Studio 2005?
Any help will be thankful if it fits into the content of this message...
Thank you..
|
|
|
|
|
You start by understanding threading and designing your app properly. Noone can tell you what to do because we know nothing of your application, data and synchronization rquirements, or anything else useful about your app. There are many different methods that can be used and various options that go with each, so it's pretty much impossible to tell you based on the information you supplied.
I suggest you start by Googling for "vb.net threading" and start reading everything you can.
|
|
|
|
|
Mr. Dave..
Thank you for being interest of such a topic..
I want to know only if it is easy to do so or not...
My application is a utility that run on windows server 2003 on computer of 4 processors..
when running this utility it will execute only on one processor and the others are not involved..
So, is multi-threading the answer to make all processors involved in executing this application. If it can be the solution, then what you think of how I could start implementing...
Thank You..
|
|
|
|
|
Whether Multithreading is the proper solution, again, depends on WHAT THE UTILITY IS DOING. Is it easy to do? That depends on what you want to have each thread do.
|
|
|
|
|
DND wrote: So, is multi-threading the answer to make all processors involved in executing this application
What is stopping you from trying it out? Operating system manages the threads and it's scheduling. On a multi-processor system, it may utilize multiple processors to execute the code in parallel or it may use time-slicing and use only one processor. You don't have any control over this.
DND wrote: If it can be the solution, then what you think of how I could start implementing...
As I said, write code and see how it behaves. Proper threading can improve application performance drastically. Threading is not very trivial. So I suggest to refer a good book before you start writing code. Here[^] is the best one you can get online.
|
|
|
|
|
Adding threads may help getting the job done sooner if:
- there are separable parts that could run concurrently (hence the algorithm isn't intrinsically sequential);
- AND you don't already have enough threads to utilize all cores.
As soon as your CPU load is close to 100%, adding threads won't help, and may even work against you.
All this assumes:
- you execute threading correctly (with sufficient synchronization);
- you don't have polling/waiting/busy loops.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
You can, of course, write a multi-threaded application using .NET. But you have no choice to decide which processor(s) each of your thread runs on. You just create your threads and start them and the runtime decides which processor(s) to run them on based on what is best for your application.
|
|
|
|
|
How many generations of garbage collection are there in .net? Why?
I was asked this question in an interview? I didn't know what exactly he meant by generations? can some help me in this question.
Thanks
KSR
|
|
|
|
|
|
AFAIK, There are 3 generations, zero, one and two.
All newly allocated objects goes into generation-0. GC walks though the object tree and marks all objects that are reachable. Garbage collection usually takes place in this generation. All the objects that are marked reachable will be promoted to generation-1 assuming these objects are long-living. unreachable objects will be cleaned up and GC compacts the heap. If these objects are again surviving collection, they will be promoted to generation-2. Garbage collection occurs very rarely on generation-2.
This generational algorithm helps GC to work efficiently. When memory is required, GC only needs to scan the generation-0 to free up the memory and other generations are scanned only when necessary. This will avoid scanning all objects that are present for an application.
|
|
|
|
|
In a simple garbage-collection system, memory is allocated from a pool. The pool always has one contiguous chunk of free memory. Each time a new object is created, the system carves off a suitable-sized piece of memory from the bottom of the free chunk. Even if some previously-allocated objects are no longer needed, and their memory could be reused, the system will carve space from bottom the free chunk until there's insufficient space left there to satisfy a request.
When that happens, the system trigger what's called a "garbage collection" cycle, which will check each previously-allocated object in order to see whether it's still used. The first object which is still in use will be moved to the bottom of the pool. The next object which is still in use will be moved immediately after it. Once all the objects have been moved, any space above the last object may be considered part of the free memory pool, from which pieces may again be carved.
Some early garbage-collection systems (like the one used in 1980's Microsoft BASIC) were horribly slow to determine which memory areas were still in use. Later systems have become much better in that regard. Nonetheless, every time a garbage collection takes place, it will generally be necessary to copy every single byte of data which still in use to a new address. This may take a considerable amount of time.
The .net garbage collection system improves upon basic garbage collection by splitting the memory pool into three parts. New allocations are made from the first part. When the first part fills up, rather than copy still-in-use items to the start of the first part, they are added to the end of the second part and the first part is then erased. When the second part fills up, still-in-use items there are copied to the end of the third part and the second part is erased. If the third part fills up, still-in-use items there will be copied to the start of the third part. Since many allocated objects are only used for a very short time, the second part of the memory pool will fill up more more slowly than the first part, and the third part will fill up even more slowly. The net effect of this is that the system's garbage collection efforts will mostly be directed toward cleaning objects which aren't in use, rather than those which are. Since the former type of operation is faster and more useful, this improves performance.
|
|
|
|
|
thanks a lot for raghu, navaneeth and supercat9. I got the answer and understood the explanation.
Thanks
KSR
|
|
|
|
|
Hi All,
I've been struggling with this for a few days now and I need some help. I've looked at the NCoverExplorer Community Forum but it seems that support questions aren't replied to at all so I thought I'd try here. I've never written a build script in my life so I'm still formly embedded in the confused state at the moment.
I'm using TeamCity 4.5, MSBuild & TTD.NET2.0 (NCoverExplorer) and the NCoverExplorer Extras with the MSBuildTask dlls. I cannot get the NCover target to actually work. My script is:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="C:\Program Files\Gallio\bin\Gallio.MSBuildTasks.dll" TaskName="Gallio" />
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCoverExplorer" AssemblyFile="$(MSBuildProjectDirectory)\Ext\MSBuild\NCoverExplorer.MSBuildTasks.dll"/>
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCover" AssemblyFile="$(MSBuildProjectDirectory)\Ext\MSBuild\NCoverExplorer.MSBuildTasks.dll"/>
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NUnitProject" AssemblyFile="$(MSBuildProjectDirectory)\Ext\MSBuild\NCoverExplorer.MSBuildTasks.dll"/>
<PropertyGroup>
<CoveragePath>$(MSBuildProjectDirectory)</CoveragePath>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="$(MSBuildProjectDirectory)\SampleSort.sln"/>
<TestAssemblies Include="$(MSBuildProjectDirectory)\SampleSort.Tests\bin\Release\SampleSort.Tests.dll"/>
<CoverageFile Include="$(CoveragePath)Reports\Coverage.xml" />
</ItemGroup>
<Target Name="Clean">
<RemoveDir Directories="Application" Condition="Exists('Application')"/>
<RemoveDir Directories="Reports" Condition="Exists('Reports')"/>
<MSBuild Projects="@(ProjectToBuild)" Targets="Clean"/>
</Target>
<Target Name="BuildSolution">
<MakeDir Directories="Application"/>
<MakeDir Directories="Application\Release"/>
<MakeDir Directories="Application\Release\Audio"/>
<MakeDir Directories="Application\Release\Audio\x64"/>
<MakeDir Directories="Application\Release\AudioFile"/>
<MakeDir Directories="Application\Release\Ext"/>
<MakeDir Directories="Application\Release\Int"/>
<MakeDir Directories="Application\Release\Help"/>
<MakeDir Directories="Application\Release\Mods"/>
<MSBuild Projects="@(ProjectToBuild)"
Targets="Rebuild"
Properties="Configuration=Release;Platform=x86">
<Output TaskParameter="TargetOutputs" ItemName="BuildOutput"/>
</MSBuild>
</Target>
<Target Name="Test">
<MakeDir Directories="Reports"/>
<Gallio IgnoreFailures="true"
Files="@(TestAssemblies)"
ReportDirectory="Reports"
ReportTypes="html"
ReportNameFormat="gallio"
ShowReports="false">
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
</Gallio>
<Error Text="Tests execution failed" Condition="'$(ExitCode)' != 0" />
</Target>
<Target Name="NCoverExplorerReport">
<NCoverExplorer
ProjectName="TestProject"
ReportType="ModuleClassSummary"
OutputDir="Reports"
XmlReportName="CoverageSummary.xml"
HtmlReportName="CoverageSummary.html"
ShowExcluded="True"
SatisfactoryCoverage="50"
CoverageFiles="@(CoverageFile)"
Exclusions="Assembly=*.Tests;Namespace=*.Tests*"
/>
</Target>
</Project>
The error message is:
Stop time: 21:42 (Total execution time: 12.877 seconds)
C:\TeamCity\buildAgent\work\b4fbc63cd7cc2d0d\SampleSort.msbuild(57,3): error MSB6001: Invalid command line switch for
"NCoverExplorer.Console.exe". Value cannot be null. C:\TeamCity\buildAgent\work\b4fbc63cd7cc2d0d\SampleSort.msbuild(57,3):
error MSB6001: Parameter name: path1
Im basically completely in the dark about how to do this. I've read so many different scripts online that all appear to do it slightly differently that I can't tell what is actually required to get this to work.
Any help really appreciated, I feel like it's groundhog day trying to get this to work.
Thanks,
|
|
|
|
|
Bit late now, but I had the same problem, and it was fixed by setting the ToolPath property in the NCoverExplorer task.
E.g.
...
<Target Name="NCoverExplorerReport">
<NCoverExplorer
ToolPath="Your\Path\To\NCoverExplorer"
...
/>
</Target>
...
Cheers,
Ergwun
modified on Thursday, June 10, 2010 8:13 PM
|
|
|
|
|
Good afternoon,
I am hoping somebody can help me with a screenshot application I am developing that has a memory leak somewhere.
The main code is as follows:
Private Sub Main()
Try
ScreenShot()
If ScreenShot() = True Then
'Calls a sub that raises an outlook email with the screenshot attached
OutlookEmail()
'This try statement will delete the temporary file created with an image of the screenshot
'This is quicker than using the clipboard and will not affect anything already on there
Try
If System.IO.File.Exists(strPath) Then
System.IO.File.Delete(strPath)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
MessageBox.Show("Failed to take a screenshot - please report to helpdesk")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function ScreenShot()
Try
Dim maxHeight As Integer = 0
Dim maxWidth As Integer = 0
For Each scr As Screen In Screen.AllScreens
maxWidth += scr.Bounds.Width
If scr.Bounds.Height > maxHeight Then maxHeight = scr.Bounds.Height
Next
Dim allScreensCapture As New Bitmap(maxWidth, maxHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim screenGrab As Bitmap = Nothing
Dim screenSize As Size = Nothing
Dim g As Graphics = Nothing
Dim g2 As Graphics = Graphics.FromImage(allScreensCapture)
Dim a As New Point(0, 0)
For Each scr As Screen In Screen.AllScreens
screenSize = New Size(scr.Bounds.Width, scr.Bounds.Height)
screenGrab = New Bitmap(scr.Bounds.Width, scr.Bounds.Height)
g = Graphics.FromImage(screenGrab)
g.CopyFromScreen(a, New Point(0, 0), screenSize)
g2.DrawImage(screenGrab, a)
a.X += scr.Bounds.Width
Next
allScreensCapture.Save(strPath, System.Drawing.Imaging.ImageFormat.Jpeg)
g.Dispose()
Return True
Catch ex As Exception
Return False
End Try
strPath = Nothing
End Function
Private Sub OutlookEmail()
'Create the outlook email, attach the screenshot and present the email to the user to send
Dim m_email As New Microsoft.Office.Interop.Outlook.Application
Dim m_message As Microsoft.Office.Interop.Outlook.MailItem = m_email.CreateItem(Interop.Outlook.OlItemType.olMailItem)
m_message.To = "test@test.co.uk"
m_message.Subject = "Screenshot of problem attached from " & System.Environment.UserName
m_message.Attachments.Add(strPath)
'display the email - dont just send it!
m_message.Display(m_email)
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
'The click method for the systray icon
Main()
End Sub
The application runs from the system tray and a clickevent handler for the notifyicon control calls the Main() sub. The code calls OutlookEmail() which creates a new outlook mail object.
The problem is that each time the notifyicon in the system tray is clicked the memory in use jumps up incrementally - about 3mb each time. I cant for the life of me find what is causing this.
Hope you can help.
|
|
|
|
|
Jordan1982 wrote:
For Each scr As Screen In Screen.AllScreens\
screenSize = New Size(scr.Bounds.Width, scr.Bounds.Height)
screenGrab = New Bitmap(scr.Bounds.Width, scr.Bounds.Height)
g = Graphics.FromImage(screenGrab)
g.CopyFromScreen(a, New Point(0, 0), screenSize)
g2.DrawImage(screenGrab, a)
a.X += scr.Bounds.Width
Next
allScreensCapture.Save(strPath, System.Drawing.Imaging.ImageFormat.Jpeg)
g.Dispose()
Since you're creating a Graphics object on every iteration of this loop, you MUST also call its Dispose method on every iteration of the loop. Move the Dispose you have after the end of the loop inside the loop. As it stands now, the only Graphics object that gets disposed is the last one you created. You can also call the Dipose method on any Bitmap objects you create, like that screenGrab .
|
|
|
|
|
Thanks for the response.
I have tried your suggestion but the Memory in use from the application increases each time the notifyicon is clicked.
Calling dispose() from the eventhandler shuts the process down entirely - even when I try to escape the closure!
Hope you can help!
|
|
|
|
|
Hi,
thanks for using PRE tags; there are many problems with your code, such as:
1.
ScreenShot() is called twice; that must be a mistake
2.
there is a lack of Dispose() calls, as Dave already mentioned.
You must dispose of each of the graphics you create, so there must also be a dispose inside the for loop.
And you must dispose of each of the bitmaps you create.
3.
Jordan1982 wrote: Catch ex As Exception
Return False
End Try
is not acceptable; you should at least log what went wrong, not just ignore it.
And the helpdesk will probably hate you for providing no clue whatsoever:
"MessageBox.Show("Failed to take a screenshot - please report to helpdesk")"
4.
Jordan1982 wrote: Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
that is better, however ex.ToString() would show more information.
5.
Jordan1982 wrote: If System.IO.File.Exists(strPath) Then
System.IO.File.Delete(strPath)
End If
No need to test, Delete() does nothing when the file doesn't exist.
6.
Jordan1982 wrote: Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
'The click method for the systray icon
Main()
End Sub
Bad choice of a method name; Main() normally is what runs first, not something called by an event handler.
[ADDED]
7.
When multiple screens are present, the user can choose the configuration; they could be side by side,
on top of each other, with a gap in between, whatever. So simply adding the widths and looking for the maximum height will fail for all but some simple side-by-side configurations.
[/ADDED]
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
hi!
I have a Form with a CrystalReportViewer control (I should say that I use embedded Crystal report in .Net 2005). there are some reports to be shown in CrystalReportViewer of course, the problem is here: after showing the reports in runtime, I can not select(by mouse) or copy any of data shown in the report page. is there any setting omitted?
every suggestion whould be appreciated
|
|
|
|
|
I am working on a component that does its own non-client area borders using NCCalcSize and NCPaint. On some computers, it works correctly, and on others it works incorrectly.
The CODE:
using(Graphics g = Graphics.FromHwnd(Handle)}
{
Rectangle backGround = new Rectangle(new Point(0, 0), Size);
Rectangle clientRect = backGround;
clientRect.Inflate(-wnd.BorderWidth, -wnd.BorderWidth);
clientRect.Height -= captionDelta;
clientRect.Y += captionDelta;
g.ExcludeClip(clientRect);
g.FillRectangle(new Pen(BackColor).Brush, new Rectangle(0, 0, Width, borderWidth + captionDelta));
int halfBorder = borderWidth / 2;
int halfCaption = wnd.CaptionHeight / 2;
bool oddSize = (borderWidth % 2) == 1;
int borderRectTop = Math.Max(wnd.CaptionHeight, 0) / 2;
Rectangle borderRect = new Rectangle(0, borderRectTop, Width - 2, Height - (borderRectTop + 2));
g.DrawRectangle(new System.Drawing.Pen(SystemColors.ButtonShadow, 1), borderRect);
borderRect.Offset(1, 1);
g.DrawRectangle(new System.Drawing.Pen(SystemColors.ButtonHighlight, 1), borderRect);
}
(I know this has undrawn pixels at top right, bottom left)
The Problem:
On some machines, this correctly draws the two rectangles inside the clipping region. On other machines, it does not. When it does not draw correctly, it is as through the excluded rectangle started one pixel earlier, and was two pixels wider than it really is.
So, if the excluded rectangle is [2,2,Width-4,Height-4], a line drawn from [0,0] to [0,Height] draws correctly, but a line drawn from [1,0] to [1,Height] only draws in the top and bottom two pixels, as though the excluded rectangle were[1,2,Width-2,Height-4].
All the machines are Dell optiplex 330s, the video driver dates are mixed, they are all using the same video chip set (NVidia 8400s, IIRC).
Does anyone know why this would happen? Is this a known bug, am I messing up somewhere, or ... ?
Urgent, please send code
Silver member by constant and unflinching longevity.
|
|
|
|
|
I'm developing a small application in which the user can open/save files. It's very simple, the possibilities are actually just like Notepad. However, with my new application I'd like to use a custom file format with a custom extension. The main thing is that I'd like to be able to store properties like labels, author, etc. in my file format and that Windows can recognize it - for example when showing it in the right columns in Details view in Windows Explorer. Does someone have an idea how I'd go about this?
Thanks.
|
|
|
|
|
You can register a file extension under HKEY_CLASSES_ROOT in the system registry such that Windows will recognise the file extension, and launch a particular application if you click on such a file. There is some useful information here[^] at MSDN. However I am not aware of anything whereby Windows will actually look at the content of a file to make such a decision.
|
|
|
|
|
Thanks for your reply.
The extension part is not the problem actually, registering it with a custom icon etc. is working well. What's the problem is the properties part that I can't manage to get information about. It's a shame you don't have an answer on that but I'll keep looking for it.
Thanks.
|
|
|
|
|
pimb2 wrote: What's the problem is the properties part that I can't manage to get information about.
I'm not sure I understand what you mean here. The contents of a file mean nothing to Windows, only to an application that reads it.
|
|
|
|
|
I mean that properties like labels and author are saved in the contents of the file, for example with Word files (.doc, .docx).
At the moment I've managed to let Windows display several properties (like labels) in the Details pane (on Vista), just like Word files. The only thing is that I have to create a so-called Property Handler which has the job to read and write properties to a file.
Thanks.
|
|
|
|
|