Regarding background or foreground thread in C#
i like to know what is background thread and what is foreground thread ?
how they are different ?
which one we should always use?
threads are by default background or foreground ?
the new Task Parallel Library use thread class or is it totally different one?
what kind of thread TPL used background or foreground ?
how TPL is different from normal thread class and ThreadPool.QueueUserWorkItem ?
looking for discussion in details with sample code. thanks
Background threads are identical to foreground threads with one exception: a background thread does not keep the managed execution environment running. Once all foreground threads have been stopped in a managed process (where the .exe file is a managed assembly),
the system stops all background threads and shuts down:
https://msdn.microsoft.com/en-us/library/h339syd0%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
>>the new Task Parallel Library use thread class or is it totally different one?
A Task resembles a thread but at a higher level of abstraction. Please refer to Jon Skeet's answer in the following thread for more information:
http://stackoverflow.com/questions/13429129/task-vs-thread-differences.
It is recommended to use the higher level abstraction (Task) wherever you can. You rarely need to explicitly start your own thread in C# 4 or later.
>>what kind of thread TPL used background or foreground ?
Background. When you create a Task, it is the responsibility of a TaskScheduler to ensure that the work of the task is eventually executed. The default TaskScheduler uses the ThreadPool under the hood to queue and execute work:
https://msdn.microsoft.com/en-us/library/dd997402(v=vs.110).aspx. And the ThreadPool creates background threads.
>>how TPL is different from normal thread class and ThreadPool.QueueUserWorkItem ?
The TPL has the advantage of being able to hook into internals of the ThreadPool that are not exposed publicly and that can boost performance in a variety of key scenarios. It scales the degree of concurrency dynamically to most efficiently use all the processors
that are available for you.
Please refer to the following MSDN blog post for more information:
http://blogs.msdn.com/b/pfxteam/archive/2009/10/06/9903475.aspx
Please only ask ONE question per thread and please remember to close your thread by marking helpful posts as answer and then start a new thread if you have a new question.
Similar Messages
-
Main Thread is Foreground thread or Background thread ?
The .NET Framework defines two types of threads: foreground and background.
By default when we create a thread, it is a foreground thread, but we can change it to a background
All processes have at least one thread of execution, which is usually called the main thread because it is the one that is executed when your program begins.
Is this main thread is back ground or foreground thread.
Regards
krrishbijuThe difference between a foreground thread/process is the priority and the parent/child ordering. A main process/thread is the parent with higher priority while the background process/thread is the child with lower priority. There is very little
different between a process and a thread. A class object is also a process.
Processes run until a blocking method stops the execution (waits for an event before continuing) or when the operating system periodically performs a task switch to allow all processes a chance to run. Processes with higher priority are allowed to
run more often than processes with lower priority.
jdweng -
Location Heuristics-diff of results in background and foreground
Hi,
We have this weekly bacth job of location heu.. just one program. nothing preceding and succeeding it.
I find the results in background and foreground different. This is partcularly wrt the receipts being created before the lead time of the loc-product. In the foreground when i delete the same receipts..and re-run the location heuristics, the receipts are correctly created . i.e obeying the lead time.
Questions:
- Why does this happen. I am doing this without anytime gap.
-Are there some settings that are called only in background (e.g from SNP global profile) but not in foreground.
Let me know if you need to know my SNP global profile settings.
The imporant ones are
HEU: Init short qty = Bakward scheduling
HEU: Order Update =Complete mode
In the location product master- NO horizons and time fences are maintained for SNP and PPDS.
Regards,
LoknathHi Loknath,
I will try to explain in with simple example.
Consider there is product xyz which exist at two different locations A & Location B.
Procurement type:
at A is Inhouse production
at B is external procurement from location A.
Both the location have some forcast/ Demand for the Product suppose 100qty each.
1. First Sequence: Now first the Heuristics needs to run at Location B so that there are Destribution receipts planned created at Location B, In other words, the Demand of Product XYZ will get transferred to Location A in form of Distributed demand Planned.
Now if you take run on Location A,
The Total demand at Location A will be 100 qty (forecast)+ 100qty( Distri.Demand from B)= 200qty and the Heuristics run will plan for the total requirement 200 qty and create the planned orders for it.
2. Second sequence: if you take heuristics at Location A first & than location B.
The planned orders generated will be only for Demand at A i.e 100 as Location A is not yet aware of the Distributed Demand which needs to be satisfied for Location B. as you have not taken the run on location B yet hence the demand is not yet transferred to Location A.
now if you take run at location B, the Distri. demand are generated to Location A but not planned or not satisfied.
Overall you see the wrong results of heuristic if you adapt second sequence.
So, it become neccesary to determine the right sequence in which the heuristic is taken for different product at different location. to determine this system use SNP low level codes.
I guess you are aware of low level code in BOM, As without exploding the Parent Material demand you cannot plan exact demand on Child material. similar principle works over here just it applies to Location Products.
Hope this helps
Regards
Kumar -
Hi All,
ME2N report displaying more columns in Background than foreground.I want same columns in Background as Foreground having 10 columns.Already i have created the default variant in foreground when i execute the report in background by proving the same variant it is displaying more columns almost 70 columns.Kindly suggest and guide me how to restrict the report to get same columns in background as in foreground.
Kindly provide is there any OSS Note available.
Thanks,
Prashanth ReddyI do not think it is possible to assign default layout for background job.
System will show you all field for background job for transaction ME2N.
Actually the screen layout is assigned with t-code (ME2N)
When the report is running in foreground, then system will take the screen layout for the t-code.
But when you run the background, then system will run the program directly (does not take the t-code). So the default screen layout will not fetch during running the background job.
For more details have a look into the thread Selecting layout in selection screen -
Image with transparent background als foreground of a button
I'd like to build an app with buttons using the phone's accent Color as Background and an Image with transparent Background as foreground of the button. It should look like the tiles on the start screen of WP8.1.
The following code doesn't work (no foreground appears)
<Button x:Name="myButton" Background="{ThemeResource PhoneAccentBrush}">
<Button.Foreground>
<ImageBrush ImageSource="/Assets/myImage.png"/>
<Button.Foreground>
</Button>
Are there any ideas?
Thanks
MartinHi mfv_technet,
The Foreground property is used to get or set a brush that describes the foreground color. So we can not bind the Foreground to a image,
if I do not misunderstand you, in my mind if we want to set the button look like the tiles on the start screen of WP8.1, maybe you can try to refer to the following xaml:
<Button x:Name="myButton" Foreground="Red" Background="{ThemeResource PhoneAccentBrush}" Margin="116,136,0,363" Width="195" Height="141">
<Button.Content>
<StackPanel Orientation="Vertical">
<Image Source="/Assets/myImage.png" Width="80" Height="80"></Image>
<TextBlock Text="Button"></TextBlock>
</StackPanel>
</Button.Content>
</Button>
The result:
If I have misunderstood you, please feel free to let me know.
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Submit Report (Regarding Background Processing)
Hi Guru's,
I want help regarding Background Processing.
I have developed a program which is running fine in forground but in Background mode no values are comming.
All values are becomig Zero.
Plz help.
*--- Submit Report for 'COGI' (Postprocessing of Error Records from Automatic Goods Movements)
SUBMIT coruaffw USING SELECTION-SCREEN '1000'
WITH r_cumul = 'X'
EXPORTING LIST TO MEMORY
AND RETURN.
*---- Get the List
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = it_list_tab
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
*--- Convert to Ascii
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listobject = it_list_tab
listasci = it_asci_tab
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE i000 WITH 'Problem in converting LIST to ASCII'.
ENDIF.
DESCRIBE TABLE it_asci_tab LINES w_cogi.
w_cogi = w_cogi - 5.
CALL FUNCTION 'LIST_FREE_MEMORY'
TABLES
listobject = it_list_tab.Hi Arbind,
You have used return you need to add the addition with.Try this way hope it works
SUBMIT zreport EXPORTING LIST TO MEMORY
AND RETURN
WITH P_1 = P_1
WITH P_2 = P_2
WITH P_3 = P_3
WITH S_4 IN S_4
WITH S_5 IN S_5
WITH S_6 IN S_6. -
BDC issue background and foreground
Hiii
i have already write bdc code using batch input. The data is taken from an excel file .
How the program work now is it create a session in SM35 and i can decide to execute the session either in background or foreground.
The reson why i did batch input and not call transaction is because i am told that with call transaction you can't execute batch input program in background since the excel file will be loaded from the user desktop. With call transaction and background execution the file need to be loaded on server first and then take the file from the server to BDC tcode.
My problem is I need my program to execute automatically without passing though the SM35. I also need to give the option to user to either execute is in foreground or background.
BDC code look this:
Call function "OPEN_BDC"
group = "ztest" I use constant
keep = "X'
perform dynpro
perform fillfield
call fuction "CLOSE_BDC"
1) I am told to use the FM file_open / file_submit / file_close but I dont really know hat parameter to pass in those FM the file_submit is giving me exception error.
2) I tried to use submit program RSBDCSUB . it create a session in sm35 and have status background job but the session havent executed
3) All the No1 and No2 is to execute the BDC in background then what about the solution if user what to execute in foreground.
Please i need precise answer??Job_submit is not functioning plzzz ess sample code below because of invalid_jobdata = 3
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobgroup = Ztest //Session name in SM35
jobname = v_jobname
IMPORTING
jobcount = v_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
authcknam = sy-uname
jobcount = v_jobcount
jobname = v_jobname
language = sy-langu
report = sy-repid
VARIANT = ' '
IMPORTING
STEP_NUMBER =
EXCEPTIONS
bad_priparams = 1
bad_xpgflags = 2
invalid_jobdata = 3
jobname_missing = 4
job_notex = 5
job_submit_failed = 6
lock_failed = 7
program_missing = 8
prog_abap_and_extpg_set = 9
OTHERS = 10
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = v_jobcount
jobname = v_jobname
sdlstrtdt = sy-uzeit
sdlstrttm = sy-datum
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
OTHERS = 9
IF sy-subrc <> 0.
ENDIF. -
Background and foreground colors can be interchanged using which command
hi
background and foreground colors can be interchanged using which command<b>Background and foreground colors can be interchanged using the command Format Inverse.</b>
-
In which way i can know that a job is running In background or foreground?
Hi,
In which way i can know that a job is running In background or foreground? please tell me...
or a report is in background or foreground..
Thanks ,
Aryacheck tranx sm37 to know all background job details
refer link
http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a8009505211d189550000e829fbbd/frameset.htm -
Hi Basis Gurus,
I have a small doubt regarding Background jobs.
Can we edit a job which is in the Scheduled status. .
If that can be done , i am unable to edit a job . When i am trying to edit the job
the message i am getting is ---
" Definition of job Z_MM_MMPV is incomplete. Operation is not
possible "
Please guide me how i can resolve this issue,
Thanks in Advance,
Vikram krishna.Hi Vikram,
Yes, this is possible.
Goto SM37 and display the Job, then select the job and from the menu: Job->Change, and click on Steps. Again select the Job and click on the change button to change whatever you want.
Hope this helps.
Thanks,
Srinivasa -
Background task using Thread? Newbie
I have a class where in it calls two different methods. However, one method requires a process over the internet.
public class MyServiceClass {
private DBService dbService;
private EmailService emailService;
public static void main(String params[]){
dbservice.insertdata(); //insert data to DB
emailService.sendEmail(); //sends email
}The process of the class takes time when running the emailService because it contacts the Internet. But the dbService is pretty quick. Do you have any idea how can I run the emailService independently that the class doesn't wait for the emailService to finish? Thanksbobgateaux wrote:
To launch new thread for email is very dangerous as of the risk that the thread can escape onto the internet and appear as virus. Always play safe by keeping the email inside the only one thread of the program - this way security is much improved.
If still worried about time taken to send email, please try to put Thread.sleep(5000) after email call - this will wait for email call to finish nicely and guarantee that program will then continue in best orderly fashion.
Best regards,
Bob Gateaux.Do threads escape you on a regular basis?
How do you have so many posts here yet show you know nada? I would think even trolling for that many posts would have lead to you picking up something, anything that might be usefull.
JSG -
Different filesize for PDF files created in background vs. foreground?
When I create a PDF file in a background job the filezise is more than 2 times bigger than created with same selection in the foreground?? Why is that? Any suggestions?
Hi Sachin,
Thanks for the thread. But it does not help us.
We should explain the issue of these sizes in little more detail.
We have a program created for PDF outputs. The PDF form is created in SFP transaction like smartform.
As you might know that a fucntion module gets created internally for the PDF form similar to a smartform.
Now during execution, the function modules(for PDF form) returns an parameter called /1bcdwb/formoutput, which has field called pdf. This field holds the entire PDF output in binery format. We use this to create a file on the appliction server. I hope you can guess why the size of the file is bigger to the file that I save the PDF output on desktop from print preview.
We are looking for a solution on how to reduce this file that gets stored on the application server using the binery data of PDF form.
Thanks and Regards,
Kiran Chevuru -
How can we know weather a report is running in background or foreground?
Is there any system variable to find it?
Hi Adiseshi,
You can check the value of the system variable SY-BATCH. If it contains the value 'X' it is running in background else in foreground.
Hope this helps!
Regards,
Saurabh -
Regarding background processing of the session
Hi Gurus
I have some records in my flat file.
While i am doing uploading the file using tc, in foreground it is processing correctly and no issues.
While in Background some of the records are not processing properly and in sm35 for those records I am getting the message :"InCorrect".
What may be the reasons I am not getting.
Can you please suggest me where may be the wrong exactly.
Your suggestions are highly encouragable.
Regards,
kumarHi Sree Ram,
This is a very common problem faced in Mass upload of data. This mainly happens if the current transaction is dependent on the previous transaction. For e.g. transaction 2 has a dependency on sucessfull processing of transaction 1.This is due to the time taken by the transaction to update the database table.
Put a commit statement after every transaction in your recording and this will ensure that the records are updated and you will not face any problem in background processing.
Regards,
Guru -
HttpConnection in background and UI thread in front causes lockups !
Hi ,
Iam running a midlet on Tre0 600 using IBM J9. (CLDC1.0/MIDP2)
The design of the midlet is as follows.
I have a main form with some items on it. (items are xml forms)
When i select a item (form) fill it and submit, i put the data to be requested in a url and send to the server. (This whole process happens in a servant thread in the background)
Once the data is qued in the servant thread, the control is given back to the main menu.
When i do this operation and the control comesback to the main menu, any action on this main screen is done only after the servant thread has got a response from the server.
If you do multiple clicks , it locks up the device and you have to do a soft reset, to recover.
I found from the logs , the device was last trying to get the response from the url.
Have anyone seen this issue ?
Is there a way in the IBM PIM pref to make this work properly ?
Appreciate your help.
Thanks and warm regards
VigneshMainPage.LayourRoot?
Maybe you are looking for
-
Please help...my screen is wacko and no one can help me
I have a toshiba satellite laptop...I bought it second hand in feb, and it was new in the fall of 08... I had no issues untill very recently it began having weird lines on the screen and freezing if I bump the screen, or move funny if its on my lap e
-
Connection problem with adobe download assistant
Hello, I'm using windows 7 and I try to install the trial version of the Master Collection cs6. I have download Adobe Download Assistant (multiple times) but every time I try to connect myself with my Adobe ID, it doesn't work. I can click on Connect
-
Call ABAP program from Unix script passing dynamic filename
Hi, Does anyone know if it is possible to call an ABAP program from a Unix script passing a dynamic filename to the ABAP program? We are receiving a file from an external company and on receipt of the file want to call an ABAP program passing the fil
-
Tab through the Close File dialogue window buttons?
In the past when closing a document or file (any app) I could Tab through the different 'Don't Save', 'Cancel' & 'Save' buttons on the close file dialogue window. And also hit the spacebar to select the highlighted button. But not any more. It could
-
how do i set the for my Live! Cam Chat Web Camera?